From 79c6459adfea528ff4f409010d94cf7660426f6f Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Thu, 22 Feb 2024 11:53:50 +0800 Subject: [PATCH] =?UTF-8?q?1.cnc=E5=B7=A5=E5=8D=95=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=96=87=E4=BB=B6=E5=AD=97=E6=AE=B52.?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E7=BC=96=E7=A8=8B=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A33.=E4=BF=AE=E5=A4=8D=E4=B8=8E=E4=B8=AD?= =?UTF-8?q?=E6=8E=A7=E5=AF=B9=E6=8E=A5=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 107 +++++++++++++++----- sf_manufacturing/models/mrp_workorder.py | 30 +++++- sf_mrs_connect/controllers/controllers.py | 5 +- 3 files changed, 110 insertions(+), 32 deletions(-) diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index d75fbe69..88f69207 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -21,27 +21,32 @@ class Manufacturing_Connect(http.Controller): datas = request.httprequest.data ret = json.loads(datas) logging.info('RfidCode:%s' % ret['RfidCode']) - workorder = request.env['mrp.workorder'].sudo().search( - [('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', '装夹预调')]) - if workorder: - for item in workorder: - res['Datas'].append({ - 'BillId': item.production_id.name, - 'ProductionLine': item.production_line, - 'CraftName': item.name, - 'Quantity': 1, - 'MaterialId': item.product_id.default_code, - 'MaterialName': item.product_id.name, - 'Spec': '%s×%s×%s' % (item.move_raw_ids.materiel_length, item.move_raw_ids.materiel_width, - item.move_raw_ids.materiel_height), - 'Material': item.product_id.materials_type_id.name - }) + if 'RfidCode' in ret: + workorder = request.env['mrp.workorder'].sudo().search( + [('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', '装夹预调')]) + if workorder: + for item in workorder: + res['Datas'].append({ + 'BillId': item.production_id.name, + 'ProductionLine': item.production_line, + 'CraftName': item.name, + 'Quantity': 1, + 'MaterialId': item.product_id.default_code, + 'MaterialName': item.product_id.name, + 'Spec': '%s×%s×%s' % (item.move_raw_ids.materiel_length, item.move_raw_ids.materiel_width, + 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: res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} logging.info('get_Work_Info error:%s' % e) 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="*") def get_ShiftPlan(self, **kw): """ @@ -54,7 +59,11 @@ class Manufacturing_Connect(http.Controller): res = {'Succeed': True, 'Datas': []} datas = request.httprequest.data 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) workorder = request.env['mrp.workorder'].sudo().search([('name', '=', ret['ProductionLine'])]) if workorder: @@ -99,17 +108,23 @@ class Manufacturing_Connect(http.Controller): res = {'Succeed': True, 'Datas': []} datas = request.httprequest.data ret = json.loads(datas) - ret = json.loads(ret['result']) logging.info('RfidCode:%s' % ret) - workorder = request.env['mrp.workorder'].sudo().search([('routing_type', '=', '前置三元定位检测')]) - if workorder: - for item in workorder: - res['Datas'].append({ - 'XOffset': item.production_id.name, - 'YOffset': item.RfidCode, - 'ZOffet': item.name, - 'COffset': 1 - }) + if 'RfidCode' in ret: + workorder = request.env['mrp.workorder'].sudo().search( + [('routing_type', '=', '前置三元定位检测'), ('rfid_code', '=', ret['RfidCode'])]) + if workorder: + for item in workorder: + offset = item.material_center_point.strip('()').split(',') + res['Datas'].append({ + '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: res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} logging.info('get_qcCheck error:%s' % e) @@ -215,3 +230,41 @@ class Manufacturing_Connect(http.Controller): res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} logging.info('Workorder_QcCheck error:%s' % e) 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) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index e4db6346..f349b6e0 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1,6 +1,7 @@ import logging import base64 -from datetime import datetime +from datetime import date +from datetime import datetime, timedelta import requests import os import math @@ -129,12 +130,30 @@ class ResMrpWorkOrder(models.Model): total_wight = fields.Float(string="总重量") maximum_carrying_weight = fields.Char(string="最大承载重量[kg]") 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="预调程序信息") workpiece_delivery_ids = fields.One2many('sf.workpiece.delivery', 'workorder_id', '工件配送') is_delivery = fields.Boolean('是否配送完成', default=False) 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') def _onchange_inspection_user_id(self): """ @@ -626,10 +645,12 @@ class CNCprocessing(models.Model): workorder_id = fields.Many2one('mrp.workorder', string="工单") production_id = fields.Many2one('mrp.production', string="制造订单") button_state = fields.Boolean(string='是否已经下发') + program_path = fields.Char('程序文件路径') # 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('program_path_ftp:%s' % program_path_ftp) for obj in ret['programming_list']: workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']), ('processing_panel', '=', obj['processing_panel']), @@ -649,7 +670,8 @@ class CNCprocessing(models.Model): 'cutting_tool_extension_length': obj['cutting_tool_extension_length'], 'cutting_tool_handle_type': obj['cutting_tool_handle_type'], '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_workorder.state = 'done' diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 5cd28a08..dee4c5f3 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import logging +import os import json import base64 from odoo import http @@ -42,8 +43,10 @@ class Sf_Mrs_Connect(http.Controller): res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name) return json.JSONEncoder().encode(res) 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.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) else: res = {'status': 0, 'message': '该制造订单暂未开始'}