From e634e9726f1cf9854d82841758623212c234bc61 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Tue, 19 Nov 2024 17:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A5=E8=89=BA=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 29 +++++++++++++++++-- .../views/mrp_production_addional_change.xml | 2 +- .../production_technology_re_adjust_wizard.py | 1 + .../wizard/production_technology_wizard.py | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index c61ba76f..e9e4d9ff 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -251,6 +251,7 @@ class MrpProduction(models.Model): remanufacture_count = fields.Integer("重新制造订单数量", compute='_compute_remanufacture_production_ids') remanufacture_production_id = fields.Many2one('mrp.production', string='') technology_design_ids = fields.One2many('sf.technology.design', 'production_id', string='工艺设计') + is_adjust = fields.Boolean('是否退回调整', default=False) @api.depends('remanufacture_production_id') def _compute_remanufacture_production_ids(self): @@ -313,7 +314,10 @@ class MrpProduction(models.Model): if not production.workorder_ids: production.state = 'technology_to_confirmed' else: - production.state = 'confirmed' + if production.is_adjust == True: + production.state = 'technology_to_confirmed' + else: + production.state = 'confirmed' elif production.state == 'pending_cam' and production.schedule_state == '未排': production.state = 'confirmed' elif production.state == 'to_close' and production.schedule_state == '已排': @@ -818,9 +822,16 @@ class MrpProduction(models.Model): self._reset_work_order_sequence1(k) return True - #需对不连续工单对应的采购单和外协出入库单做处理 + # 需对不连续工单对应的采购单和外协出入库单做处理 def _reset_subcontract_pick_purchase(self): - for item in self: + production_all = self.sorted(lambda x: x.id) + product_id_to_production_names = {} + grouped_product_ids = {k: list(g) for k, g in + groupby(production_all, key=lambda x: x.product_id.id)} + for product_id, pd in grouped_product_ids.items(): + product_id_to_production_names[product_id] = [p.name for p in pd] + for item in production_all: + production_process = product_id_to_production_names.get(item.product_id.id) workorder_sf = item.workorder_ids.filtered(lambda sf: sf.routing_type == '表面工艺') for i, workorder in enumerate(workorder_sf): if i == 0: @@ -828,6 +839,18 @@ class MrpProduction(models.Model): elif workorder.sequence != workorder_sf[i - 1].sequence + 1: # workorder.picking_ids.move_ids = False workorder.picking_ids = False + purchase_order = self.env['purchase.order'].search( + [('state', '=', 'draft'), ('origin', '=', ','.join(production_process)), + ('purchase_type', '=', 'consignment')]) + for line in purchase_order.order_line: + server_template = self.env['product.template'].search( + [('server_product_process_parameters_id', '=', workorder.surface_technics_parameters_id.id), + ('detailed_type', '=', 'service')]) + purchase_order_line = self.env['purchase.order.line'].search( + [('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id), + ('product_qty', '=', len(production_process))], limit=1, order='id desc') + if purchase_order_line: + line.unlink() def _reset_work_order_sequence(self): """ diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index f88182cb..99b1e4ba 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -353,7 +353,7 @@ - + diff --git a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py index 00a8f668..02b0063e 100644 --- a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py +++ b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py @@ -105,6 +105,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): productions._reset_work_order_sequence() productions._reset_subcontract_pick_purchase() productions.get_subcontract_pick_purchase() + productions.is_adjust = True for item in productions: workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( key=lambda a: a.sequence) diff --git a/sf_manufacturing/wizard/production_technology_wizard.py b/sf_manufacturing/wizard/production_technology_wizard.py index 2293dc73..24e61014 100644 --- a/sf_manufacturing/wizard/production_technology_wizard.py +++ b/sf_manufacturing/wizard/production_technology_wizard.py @@ -57,6 +57,7 @@ class ProductionTechnologyWizard(models.TransientModel): # # if special: productions._create_workorder(False) productions.get_subcontract_pick_purchase() + productions.is_adjust = False for item in productions: workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( key=lambda a: a.sequence)