1.cnc工单新增程序文件字段2.优化获取编程单接口3.修复与中控对接的接口

This commit is contained in:
jinling.yang
2024-02-22 11:53:50 +08:00
parent ef3219a098
commit 79c6459adf
3 changed files with 110 additions and 32 deletions

View File

@@ -21,27 +21,32 @@ class Manufacturing_Connect(http.Controller):
datas = request.httprequest.data datas = request.httprequest.data
ret = json.loads(datas) ret = json.loads(datas)
logging.info('RfidCode:%s' % ret['RfidCode']) logging.info('RfidCode:%s' % ret['RfidCode'])
workorder = request.env['mrp.workorder'].sudo().search( if 'RfidCode' in ret:
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', '装夹预调')]) workorder = request.env['mrp.workorder'].sudo().search(
if workorder: [('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', '装夹预调')])
for item in workorder: if workorder:
res['Datas'].append({ for item in workorder:
'BillId': item.production_id.name, res['Datas'].append({
'ProductionLine': item.production_line, 'BillId': item.production_id.name,
'CraftName': item.name, 'ProductionLine': item.production_line,
'Quantity': 1, 'CraftName': item.name,
'MaterialId': item.product_id.default_code, 'Quantity': 1,
'MaterialName': item.product_id.name, 'MaterialId': item.product_id.default_code,
'Spec': '%s×%s×%s' % (item.move_raw_ids.materiel_length, item.move_raw_ids.materiel_width, 'MaterialName': item.product_id.name,
item.move_raw_ids.materiel_height), 'Spec': '%s×%s×%s' % (item.move_raw_ids.materiel_length, item.move_raw_ids.materiel_width,
'Material': item.product_id.materials_type_id.name item.move_raw_ids.materiel_height),
}) 'Material': item.product_id.materials_type_id.name
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该rfid暂未有对应的工单'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e: except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('get_Work_Info error:%s' % e) logging.info('get_Work_Info error:%s' % e)
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/GetShiftPlan', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, @http.route('/AutoDeviceApi/GetShiftPlan', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*") cors="*")
def get_ShiftPlan(self, **kw): def get_ShiftPlan(self, **kw):
""" """
@@ -54,7 +59,11 @@ class Manufacturing_Connect(http.Controller):
res = {'Succeed': True, 'Datas': []} res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data datas = request.httprequest.data
ret = json.loads(datas) ret = json.loads(datas)
ret = json.loads(ret['result']) if 'ProductionLine' in ret:
workorder = request.env['mrp.workorder'].sudo().get_plan_workorder(ret['ProductionLine'])
else:
ProductionLine = False
workorder = request.env['mrp.workorder'].sudo().get_plan_workorder(ProductionLine)
logging.info('RfidCode:%s' % ret) logging.info('RfidCode:%s' % ret)
workorder = request.env['mrp.workorder'].sudo().search([('name', '=', ret['ProductionLine'])]) workorder = request.env['mrp.workorder'].sudo().search([('name', '=', ret['ProductionLine'])])
if workorder: if workorder:
@@ -99,17 +108,23 @@ class Manufacturing_Connect(http.Controller):
res = {'Succeed': True, 'Datas': []} res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data datas = request.httprequest.data
ret = json.loads(datas) ret = json.loads(datas)
ret = json.loads(ret['result'])
logging.info('RfidCode:%s' % ret) logging.info('RfidCode:%s' % ret)
workorder = request.env['mrp.workorder'].sudo().search([('routing_type', '=', '前置三元定位检测')]) if 'RfidCode' in ret:
if workorder: workorder = request.env['mrp.workorder'].sudo().search(
for item in workorder: [('routing_type', '=', '前置三元定位检测'), ('rfid_code', '=', ret['RfidCode'])])
res['Datas'].append({ if workorder:
'XOffset': item.production_id.name, for item in workorder:
'YOffset': item.RfidCode, offset = item.material_center_point.strip('()').split(',')
'ZOffet': item.name, res['Datas'].append({
'COffset': 1 'XOffset': item.production_id.name,
}) 'YOffset': item.RfidCode,
'ZOffet': item.name,
'COffset': item.X_deviation_angle
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该rfid暂未有对应的工件预调(前置三元检测)工单'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e: except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('get_qcCheck error:%s' % e) logging.info('get_qcCheck error:%s' % e)
@@ -215,3 +230,41 @@ class Manufacturing_Connect(http.Controller):
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('Workorder_QcCheck error:%s' % e) logging.info('Workorder_QcCheck error:%s' % e)
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/NCProgDolod', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def NCProgDolod(self, **kw):
"""
中控系统传递RFID编号给MES获取程序单及程序文件。Ftp下载文件
:param kw:
:return:
"""
logging.info('NCProgDolod:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
if 'RfidCode' in ret:
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工')])
if workorder:
for item in workorder.cnc_ids:
res['Datas'].append({
'CraftId': workorder.id,
'CraftName': workorder.name,
'SortId': item.sequence_number,
'ProgramName': item.program_name,
'ToolId': item.cutting_tool_no,
'ToolName': item.cutting_tool_name,
'Depth': item.depth_of_processing_z,
'ProgramPath': item.program_path,
'ProgramTime': item.estimated_processing_time,
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '暂无工单及对应的CNC程序数据'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('NCProgDolod error:%s' % e)
return json.JSONEncoder().encode(res)

View File

@@ -1,6 +1,7 @@
import logging import logging
import base64 import base64
from datetime import datetime from datetime import date
from datetime import datetime, timedelta
import requests import requests
import os import os
import math import math
@@ -129,12 +130,30 @@ class ResMrpWorkOrder(models.Model):
total_wight = fields.Float(string="总重量") total_wight = fields.Float(string="总重量")
maximum_carrying_weight = fields.Char(string="最大承载重量[kg]") maximum_carrying_weight = fields.Char(string="最大承载重量[kg]")
maximum_clamping_force = fields.Char(string="最大夹持力[n]") maximum_clamping_force = fields.Char(string="最大夹持力[n]")
production_line = fields.Char(string="生产线") production_line_id = fields.Many2one('sf.production.line', string="生产线")
preset_program_information = fields.Char(string="预调程序信息") preset_program_information = fields.Char(string="预调程序信息")
workpiece_delivery_ids = fields.One2many('sf.workpiece.delivery', 'workorder_id', '工件配送') workpiece_delivery_ids = fields.One2many('sf.workpiece.delivery', 'workorder_id', '工件配送')
is_delivery = fields.Boolean('是否配送完成', default=False) is_delivery = fields.Boolean('是否配送完成', default=False)
rfid_code = fields.Char('RFID') rfid_code = fields.Char('RFID')
def get_plan_workorder(self, production_line):
tomorrow = (date.today() + timedelta(days=+1)).strftime("%Y-%m-%d")
sql = """
SELECT *
FROM mrp_workorder
WHERE date_planned_start = %s::timestamp
AND date_planned_start < (%s::timestamp + interval '1 day')
AND date_planned_finished >= %s::timestamp
AND date_planned_finished < (%s::timestamp + interval '1 day')
"""
params = [tomorrow, tomorrow, tomorrow, tomorrow]
if production_line:
sql += "AND production_line_id = %s"
params.append(production_line)
self.env.cr.execute(sql, params)
ids = [t[0] for t in self.env.cr.fetchall()]
return [('id', 'in', ids)]
@api.onchange('is_ok') @api.onchange('is_ok')
def _onchange_inspection_user_id(self): def _onchange_inspection_user_id(self):
""" """
@@ -626,10 +645,12 @@ class CNCprocessing(models.Model):
workorder_id = fields.Many2one('mrp.workorder', string="工单") workorder_id = fields.Many2one('mrp.workorder', string="工单")
production_id = fields.Many2one('mrp.production', string="制造订单") production_id = fields.Many2one('mrp.production', string="制造订单")
button_state = fields.Boolean(string='是否已经下发') button_state = fields.Boolean(string='是否已经下发')
program_path = fields.Char('程序文件路径')
# mrs下发编程单创建CNC加工 # mrs下发编程单创建CNC加工
def cnc_processing_create(self, cnc_workorder, ret): def cnc_processing_create(self, cnc_workorder, ret, program_path_ftp):
logging.info('ret:%s' % ret) logging.info('ret:%s' % ret)
logging.info('program_path_ftp:%s' % program_path_ftp)
for obj in ret['programming_list']: for obj in ret['programming_list']:
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']), workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']),
('processing_panel', '=', obj['processing_panel']), ('processing_panel', '=', obj['processing_panel']),
@@ -649,7 +670,8 @@ class CNCprocessing(models.Model):
'cutting_tool_extension_length': obj['cutting_tool_extension_length'], 'cutting_tool_extension_length': obj['cutting_tool_extension_length'],
'cutting_tool_handle_type': obj['cutting_tool_handle_type'], 'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
'estimated_processing_time': obj['estimated_processing_time'], 'estimated_processing_time': obj['estimated_processing_time'],
'remark': obj['remark'] 'remark': obj['remark'],
'program_path': '%s/%s' % (program_path_ftp, obj['program_name'])
}) })
cnc_processing.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel) cnc_processing.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
# cnc_workorder.state = 'done' # cnc_workorder.state = 'done'

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
import os
import json import json
import base64 import base64
from odoo import http from odoo import http
@@ -42,8 +43,10 @@ class Sf_Mrs_Connect(http.Controller):
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name) res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name)
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
logging.info('创建cnc工单') logging.info('创建cnc工单')
program_path_ftp = os.path.join('/', ret['folder_name'], 'return', r)
logging.info('cnc程序路径 :%s' % program_path_ftp)
request.env['sf.cnc.processing'].with_user( request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret) request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path_ftp)
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
else: else:
res = {'status': 0, 'message': '该制造订单暂未开始'} res = {'status': 0, 'message': '该制造订单暂未开始'}