From 9a7ac4dfa69f236f1c5846a7a876374aa771cef8 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Fri, 9 Aug 2024 17:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=B6=E9=80=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=8A=A5=E5=BA=9F=E5=90=91=E5=AF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 5 +- .../views/mrp_production_addional_change.xml | 2 +- sf_manufacturing/views/mrp_workorder_view.xml | 2 +- sf_manufacturing/wizard/production_wizard.py | 77 ++++++++++++++++--- .../wizard/production_wizard_views.xml | 6 +- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 4caa5499..3384ab4c 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -918,7 +918,7 @@ class MrpProduction(models.Model): logging.info('get_new_program error:%s' % e) raise UserError("从云平台获取最新程序失败,请联系管理员") - def recreateManufacturing(self): + def recreateManufacturing(self, item): """ 重新生成制造订单 """ @@ -930,7 +930,7 @@ class MrpProduction(models.Model): values) # self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) - productions._create_workorder() + productions._create_workorder(item) productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \ ( p.move_dest_ids.procure_method != 'make_to_order' and @@ -1023,6 +1023,7 @@ class MrpProduction(models.Model): 'product_id': productions.product_id.id, 'state': 'draft', }) + return productions # 在之前的销售单上重新生成制造订单 def create_production1_values(self, production, sale_order): diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index be887cc5..5825cb9f 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -70,7 +70,7 @@ - confirmed,pending_cam,progress,rework,scrapdone + confirmed,pending_cam,progress,rework,scrap,done diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 0c4fcd38..5df3ebf2 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -202,7 +202,7 @@ - diff --git a/sf_manufacturing/wizard/production_wizard.py b/sf_manufacturing/wizard/production_wizard.py index aa484a9e..28a43419 100644 --- a/sf_manufacturing/wizard/production_wizard.py +++ b/sf_manufacturing/wizard/production_wizard.py @@ -17,13 +17,70 @@ class ProductionWizard(models.TransientModel): def confirm(self): if self.is_reprogramming is True: self.production_id.update_programming_state() - self.production_id.action_cancel() - self.production_id.detection_result_ids.write({'handle_result': '已处理'}) - self.production_id.write({'state': 'cancel', 'scrap_ids': [(0, 0, { - 'name': self.env['ir.sequence'].next_by_code('stock.scrap') or _('New'), - 'product_id': self.production_id.product_id.id, - 'scrap_qty': 1, - 'lot_id': self.production_id.move_line_raw_ids.lot_id.id, - 'location_id': self.production_id.move_raw_ids.filtered(lambda x: x.state not in ( - 'done', 'cancel')) and self.production_id.location_src_id.id or self.production_id.location_dest_id.id, - 'scrap_location_id': self.env['stock.scrap']._get_default_scrap_location_id(), 'state': 'done'})]}) + if self.is_remanufacture is True: + ret = {'programming_list': []} + scrap_cnc = self.production_id.workorder_ids.filtered(lambda crw: crw.routing_type == 'CNC加工').cnc_ids + scrap_cmm = self.production_id.workorder_ids.filtered(lambda cm: cm.routing_type == 'CNC加工').cmm_ids + for item_line in scrap_cnc: + vals = { + 'sequence_number': item_line.sequence_number, + 'program_name': item_line.program_name, + 'cutting_tool_name': item_line.cutting_tool_name, + 'cutting_tool_no': item_line.cutting_tool_no, + 'processing_type': item_line.processing_type, + 'margin_x_y': item_line.margin_x_y, + 'margin_z': item_line.margin_z, + 'depth_of_processing_z': item_line.depth_of_processing_z, + 'cutting_tool_extension_length': item_line.cutting_tool_extension_length, + 'estimated_processing_time': item_line.estimated_processing_time, + 'cutting_tool_handle_type': item_line.cutting_tool_handle_type, + 'ftp_path': item_line.program_path, + 'processing_panel': item_line.workorder_id.processing_panel, + 'program_create_date': datetime.strftime(item_line.program_create_date, + '%Y-%m-%d %H:%M:%S'), + 'remark': item_line.remark + } + ret['programming_list'].append(vals) + for cmm_line in scrap_cmm: + vals = { + 'sequence_number': cmm_line.sequence_number, + 'program_name': cmm_line.program_name, + 'ftp_path': cmm_line.program_path, + 'processing_panel': item_line.workorder_id.processing_panel, + 'program_create_date': datetime.strftime( + cmm_line.program_create_date, + '%Y-%m-%d %H:%M:%S') + } + ret['programming_list'].append(vals) + new_production = self.production_id.recreateManufacturing(ret) + if self.is_reprogramming is False: + for panel in new_production.product_id.model_processing_panel: + scrap_cnc_workorder = max( + self.production_id.workorder_ids.filtered( + lambda + scn: scn.processing_panel == panel.name and scn.cnc_worksheet and scn.routing_type == 'CNC加工'), + key=lambda w: w.create_date) + scrap_pre_workorder = max(self.production_id.workorder_ids.filtered( + lambda + pr: pr.processing_panel == panel.name and pr.processing_drawing and pr.routing_type == '装夹预调'), + key=lambda w1: w1.create_date) + new_cnc_workorder = new_production.workorder_ids.filtered( + lambda + nc: nc.processing_panel == panel and nc.routing_type == 'CNC加工') + new_cnc_workorder.write({'cnc_worksheet': scrap_cnc_workorder.cnc_worksheet}) + new_pre_workorder = new_production.workorder_ids.filtered(lambda + p: p.routing_type == '装夹预调' and p.processing_panel == panel) + new_pre_workorder.write({'processing_drawing': scrap_pre_workorder.processing_drawing}) + + +if new_pre_workorder: + self.production_id.action_cancel() + self.production_id.detection_result_ids.write({'handle_result': '已处理'}) + self.production_id.write({'state': 'cancel', 'scrap_ids': [(0, 0, { + 'name': self.env['ir.sequence'].next_by_code('stock.scrap') or _('New'), + 'product_id': self.production_id.product_id.id, + 'scrap_qty': 1, + 'lot_id': self.production_id.move_line_raw_ids.lot_id.id, + 'location_id': self.production_id.move_raw_ids.filtered(lambda x: x.state not in ( + 'done', 'cancel')) and self.production_id.location_src_id.id or self.production_id.location_dest_id.id, + 'scrap_location_id': self.env['stock.scrap']._get_default_scrap_location_id(), 'state': 'done'})]}) diff --git a/sf_manufacturing/wizard/production_wizard_views.xml b/sf_manufacturing/wizard/production_wizard_views.xml index 94bf4245..5ce6d43a 100644 --- a/sf_manufacturing/wizard/production_wizard_views.xml +++ b/sf_manufacturing/wizard/production_wizard_views.xml @@ -9,11 +9,11 @@
重新生成制造订单 - +
-
+
申请重新编程 - +