From 750183263782a3ee08131a2bc202d4a24bc45e30 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Tue, 13 May 2025 10:01:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=8B=A8=E5=8D=95=E5=B0=B1=E7=BB=AA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/purchase_order.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index 7d5d6161..5b4a6e4b 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -121,16 +121,21 @@ class PurchaseOrder(models.Model): if not is_available: raise UserError('请先完成坯料入库') for production_id in productions: - picking_id = production_id.picking_ids.filtered( + work_ids = production_id.workorder_ids.filtered( + lambda wk: wk.state not in ['done', 'rework', 'cancel']) + if not work_ids: + continue + min_sequence_wk = min(work_ids, key=lambda wk: wk.sequence) + if min_sequence_wk.is_subcontract: + picking_id = production_id.picking_ids.filtered( lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区') - move_out = picking_id.move_ids - for mo in move_out: - if mo.state != 'done': - mo.write({'state': 'assigned', 'production_id': False}) - if not mo.move_line_ids: - self.env['stock.move.line'].create( - mo.get_move_line(production_id,False)) - + move_out = picking_id.move_ids + for mo in move_out: + if mo.state != 'done': + mo.write({'state': 'assigned', 'production_id': False}) + if not mo.move_line_ids: + self.env['stock.move.line'].create( + mo.get_move_line(production_id, min_sequence_wk)) # product = self.env['mrp.production'].search([('product_id', '=', product_id)], limit=1) # match = re.search(r'(S\d{5}-\d)',product.name) # pass