diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index dda99bfb..da54f77b 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -297,7 +297,7 @@ class MrpProduction(models.Model): def update_programming_state(self): try: manufacturing_type = 'rework' - if self.is_scrap is False: + if self.is_scrap: manufacturing_type = 'scrap' elif self.tool_state == '2': manufacturing_type = 'invalid_tool_rework' diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 50383a19..37132097 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -25,7 +25,7 @@ class Sf_Mrs_Connect(http.Controller): ret = json.loads(ret['result']) logging.info('下发编程单:%s' % ret) domain = [('programming_no', '=', ret['programming_no'])] - if ret['manufacturing_type'] == 'scrap': + if ret['manufacturing_type'] in ('scrap', 'invalid_tool_rework'): domain += [('state', 'not in', ['done', 'scrap', 'cancel'])] productions = request.env['mrp.production'].with_user( request.env.ref("base.user_admin")).search(domain) diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 56993ddb..c6a04196 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -314,27 +314,28 @@ class CAMWorkOrderProgramKnifePlan(models.Model): 'applicant': None, 'sf_functional_tool_assembly_id': None}) - def create_cam_work_plan(self, cnc_processing, missing_tools): + def create_cam_work_plan(self, cnc_ids): """ 根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划 """ # 获取编程单号 - programming_no = cnc_processing.workorder_id.production_id.programming_no + programming_no = cnc_ids[0].workorder_id.production_id.programming_no logging.info(f'编程单号:{programming_no}') - for missing_tool in missing_tools: + for cnc_processing in cnc_ids: + tool_name = cnc_processing.cutting_tool_name cam_id = self.env['sf.cam.work.order.program.knife.plan'].sudo().search( [('programming_no', '=', programming_no), - ('functional_tool_name', '=', missing_tool)]) + ('functional_tool_name', '=', tool_name)]) if cam_id: - logging.info(f'CAM装刀计划:{cam_id}') + logging.info(f'编程单号{programming_no}功能刀具名称{tool_name}已存在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, + 'functional_tool_name': 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), @@ -344,9 +345,10 @@ class CAMWorkOrderProgramKnifePlan(models.Model): 'shank_model': cnc_processing.cutting_tool_handle_type, 'estimated_processing_time': cnc_processing.estimated_processing_time, }) - logging.info('CAM工单程序用刀计划创建成功!!!') + logging.info(f'创建CAM工单程序用刀计划:{knife_plan}') # 创建装刀请求 knife_plan.apply_for_tooling() + logging.info('CAM工单程序用刀计划创建已完成!!!') 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 2fd58354..96198cbb 100644 --- a/sf_tool_management/models/mrp_workorder.py +++ b/sf_tool_management/models/mrp_workorder.py @@ -192,6 +192,7 @@ class MrpProduction(models.Model): 'handle_result': '待处理' }) # 自动调用重新获取编程的方法 + logging.info('cnc用刀校验到无效刀自动调用重新编程方法:update_programming_state()') self[0].update_programming_state() # 修改制造订单 编程状态变为“编程中” self.write({'programming_state': '编程中', 'work_state': '编程中'}) @@ -203,10 +204,10 @@ class MrpProduction(models.Model): 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)]) + [('workorder_id', 'in', workorder_ids.filtered(lambda a: a.production_id == self[0].id).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('调用CAM工单程序用刀计划创建方法!!!') + self.env['sf.cam.work.order.program.knife.plan'].sudo().create_cam_work_plan(cnc_ids) logging.info('工单cnc程序用刀校验完成!!!')