diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 59ce68ab..dda99bfb 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -296,8 +296,13 @@ class MrpProduction(models.Model): # 编程单更新 def update_programming_state(self): try: + manufacturing_type = 'rework' + if self.is_scrap is False: + manufacturing_type = 'scrap' + elif self.tool_state == '2': + manufacturing_type = 'invalid_tool_rework' res = {'programming_no': self.programming_no, - 'manufacturing_type': 'rework' if self.is_scrap is False else 'scrap'} + 'manufacturing_type': manufacturing_type} logging.info('res=%s:' % res) configsettings = self.env['res.config.settings'].get_values() config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key']) diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 7f3c3d83..50383a19 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -96,6 +96,10 @@ class Sf_Mrs_Connect(http.Controller): res.update({ 'production_ids': productions.ids }) + + # 对制造订单所以面的cnc工单的程序用刀进行校验 + productions.production_cnc_tool_checkout() + return json.JSONEncoder().encode(res) else: res = {'status': 0, 'message': '该制造订单暂未开始'} diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 33ab0790..56993ddb 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -314,7 +314,7 @@ class CAMWorkOrderProgramKnifePlan(models.Model): 'applicant': None, 'sf_functional_tool_assembly_id': None}) - def create_cam_work_plan(self, cnc_processing): + def create_cam_work_plan(self, cnc_processing, missing_tools): """ 根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划 """ @@ -322,29 +322,31 @@ class CAMWorkOrderProgramKnifePlan(models.Model): # 获取编程单号 programming_no = cnc_processing.workorder_id.production_id.programming_no logging.info(f'编程单号:{programming_no}') - cam_id = self.env['sf.cam.work.order.program.knife.plan'].sudo().search( - [('programming_no', '=', programming_no), - ('functional_tool_name', '=', cnc_processing.cutting_tool_name)]) - logging.info(f'CAM装刀计划:{cam_id}') - if not cam_id: - knife_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().create({ - 'name': cnc_processing.workorder_id.production_id.name, - 'programming_no': programming_no, - 'cam_procedure_code': cnc_processing.program_name, - 'filename': cnc_processing.cnc_id.name, - 'functional_tool_name': cnc_processing.cutting_tool_name, - 'cam_cutter_spacing_code': cnc_processing.cutting_tool_no, - 'process_type': cnc_processing.processing_type, - 'margin_x_y': float(cnc_processing.margin_x_y), - 'margin_z': float(cnc_processing.margin_z), - 'finish_depth': float(cnc_processing.depth_of_processing_z), - 'extension_length': float(cnc_processing.cutting_tool_extension_length), - 'shank_model': cnc_processing.cutting_tool_handle_type, - 'estimated_processing_time': cnc_processing.estimated_processing_time, - }) - logging.info('CAM工单程序用刀计划创建成功!!!') - # 创建装刀请求 - knife_plan.apply_for_tooling() + for missing_tool in missing_tools: + cam_id = self.env['sf.cam.work.order.program.knife.plan'].sudo().search( + [('programming_no', '=', programming_no), + ('functional_tool_name', '=', missing_tool)]) + if cam_id: + logging.info(f'CAM装刀计划:{cam_id}') + else: + knife_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().create({ + 'name': cnc_processing.workorder_id.production_id.name, + 'programming_no': programming_no, + 'cam_procedure_code': cnc_processing.program_name, + 'filename': cnc_processing.cnc_id.name, + 'functional_tool_name': missing_tool, + 'cam_cutter_spacing_code': cnc_processing.cutting_tool_no, + 'process_type': cnc_processing.processing_type, + 'margin_x_y': float(cnc_processing.margin_x_y), + 'margin_z': float(cnc_processing.margin_z), + 'finish_depth': float(cnc_processing.depth_of_processing_z), + 'extension_length': float(cnc_processing.cutting_tool_extension_length), + 'shank_model': cnc_processing.cutting_tool_handle_type, + 'estimated_processing_time': cnc_processing.estimated_processing_time, + }) + logging.info('CAM工单程序用刀计划创建成功!!!') + # 创建装刀请求 + knife_plan.apply_for_tooling() def unlink_cam_plan(self, production): for item in production: diff --git a/sf_tool_management/models/mrp_workorder.py b/sf_tool_management/models/mrp_workorder.py index ce63c25d..2fd58354 100644 --- a/sf_tool_management/models/mrp_workorder.py +++ b/sf_tool_management/models/mrp_workorder.py @@ -29,7 +29,7 @@ class CNCprocessing(models.Model): # else: # raise ValidationError("MES装刀指令发送失败") - def cnc_tool_checkout(self, cnc_processing_ids): + def cnc_tool_checkout_1(self, cnc_processing_ids): """ 根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划 """ @@ -128,13 +128,6 @@ class CNCprocessing(models.Model): }) logging.info('工单cnc程序用刀校验已完成!') - @api.model_create_multi - def create(self, vals): - obj = super(CNCprocessing, self).create(vals) - # 调用CAM工单程序用刀计划创建方法 - self.cnc_tool_checkout(obj) - return obj - class MrpWorkCenter(models.Model): _inherit = 'mrp.workcenter' @@ -143,3 +136,77 @@ class MrpWorkCenter(models.Model): action = self.env.ref('sf_tool_management.sf_functional_tool_assembly_view_act') result = action.read()[0] return result + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + def production_cnc_tool_checkout(self): + logging.info('开始进行工单cnc程序用刀校验!!!') + invalid_tool = [] # 无效刀 + invalid_tool_processing_panel = [] # 无效刀加工面 + missing_tool_1 = [] # 缺刀(机内、线边) + missing_tool_2 = [] # 缺刀(库存) + for item in self: + workorder_ids = item.workorder_ids.filtered(lambda a: a.state not in ['rework', 'cancel']) + for workorder_id in workorder_ids: + if workorder_id.cnc_ids: + for cnc_id in workorder_id.cnc_ids: + tool_name = cnc_id.cutting_tool_name + # 查询功能刀具在清单中是否存在 + tool_inventory_id = self.env['sf.tool.inventory'].sudo().search([('name', '=', tool_name)]) + if not tool_inventory_id: + invalid_tool.append(tool_name) + invalid_tool_processing_panel.append(workorder_id.processing_panel) + continue + # 查询功能刀具是否存在库存 + functional_tools = self.env['sf.functional.cutting.tool.entity'].sudo().search( + [('tool_name_id', '=', tool_inventory_id.id), ('functional_tool_status', '=', '正常')]) + if not functional_tools.filtered(lambda p: p.current_location in ('线边刀库', '机内刀库')): + missing_tool_1.append(tool_name) # 判断为 ('线边刀库', '机内刀库') 缺刀 + if not functional_tools: + missing_tool_2.append(tool_name) # 判断为 库存缺刀 + break + # 修改cnc程序的‘刀具状态’ + workorder_ids = self.env['mrp.workorder'].sudo().search([('production_id', 'in', self.ids)]) + if invalid_tool: + # 修改cnc程序的‘刀具状态’为 ‘无效刀’ + cnc_ids = self.env['sf.cnc.processing'].sudo().search( + [('workorder_id', 'in', workorder_ids.ids), ('cutting_tool_name', 'in', invalid_tool)]) + if cnc_ids: + cnc_ids.write({'tool_state': '2'}) + # 创建制造订单无效刀检测结果记录 + for production_id in self: + for processing_panel in list(set(invalid_tool_processing_panel)): + if not production_id.detection_result_ids.filtered( + lambda a: (a.processing_panel == processing_panel and a.detailed_reason == '无效功能刀具' + and a.handle_result == '待处理' and a.routing_type == 'CNC加工' + and a.rework_reason == 'programming' and a.test_results == '返工')): + production_id.detection_result_ids.create({ + 'production_id': production_id.id, + 'processing_panel': processing_panel, + 'routing_type': 'CNC加工', + 'rework_reason': 'programming', # 原因:编程(programming) + 'detailed_reason': '无效功能刀具', + 'test_results': '返工', + 'handle_result': '待处理' + }) + # 自动调用重新获取编程的方法 + self[0].update_programming_state() + # 修改制造订单 编程状态变为“编程中” + self.write({'programming_state': '编程中', 'work_state': '编程中'}) + if missing_tool_1: + # 修改 修改cnc程序的‘刀具状态’ 为 ‘缺刀’ + cnc_ids = self.env['sf.cnc.processing'].sudo().search( + [('workorder_id', 'in', workorder_ids.ids), ('cutting_tool_name', 'in', missing_tool_1)]) + if cnc_ids: + cnc_ids.write({'tool_state': '1'}) + if missing_tool_2 and not invalid_tool: + # 调用CAM工单程序用刀计划创建方法 + logging.info('调用CAM工单程序用刀计划创建方法!!!') + cnc_ids = self.env['sf.cnc.processing'].sudo().search( + [('workorder_id', 'in', workorder_ids.ids), ('cutting_tool_name', 'in', missing_tool_2)]) + if cnc_ids: + self.env['sf.cam.work.order.program.knife.plan'].sudo().create_cam_work_plan(cnc_ids[0], list( + set(missing_tool_2))) + logging.info('工单cnc程序用刀校验完成!!!')