diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 960d4b14..749ceafe 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -868,17 +868,25 @@ class MrpProduction(models.Model): raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no)) productions = self.env['mrp.production'].search( [('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))]) + logging.info('get_new_program productions:%s' % productions) if productions: - panel_workorder = productions.workorder_ids.filtered( - lambda - ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state not in ( - 'rework', 'done')) + workorder_ids = set() + for production in productions: + for workorder in production.workorder_ids: + if workorder.processing_panel == processing_panel and workorder.routing_type == 'CNC加工' and workorder.state not in ( + 'rework', 'done'): + workorder_ids.add(workorder.id) + panel_workorder = self.env['mrp.workorder'].search([('id', 'in', list(workorder_ids))]) + logging.info('get_new_program panel_workorder:%s' % panel_workorder) if panel_workorder: if panel_workorder.cnc_ids: + logging.info('get_new_program 1') panel_workorder.cmm_ids.sudo().unlink() panel_workorder.cnc_ids.sudo().unlink() + logging.info('get_new_program 2') self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( productions) + logging.info('get_new_program 3') # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', # processing_panel) logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) @@ -889,15 +897,19 @@ class MrpProduction(models.Model): if file_extension.lower() == '.pdf': panel_file_path = os.path.join(program_path_tmp_panel, file) logging.info('panel_file_path:%s' % panel_file_path) + logging.info('get_new_program 4') panel_workorder.write( {'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, result), 'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, result), 'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) + logging.info('get_new_program 5') pre_workorder = productions.workorder_ids.filtered(lambda ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state != 'rework') + logging.info('get_new_program 6') if pre_workorder: pre_workorder.write( {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) + logging.info('get_new_program 7') else: raise UserError(result['message']) except Exception as e: