From 9647620a91a0c8597eff0dd4361f8a2b8e0997ed Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 14 Mar 2018 14:11:25 +0100 Subject: [PATCH] [FIX] mrp: workorders of sub-BOMs - Create the following BOM structure: ``` Prod 1 (Manufacture) | --- Prod 2 Prod 3 (Kit) | --- Prod 4 Prod 5 ``` - The BOMs for Prod 1 & 3 must have a routing set, to generate workorders - Create a MO for 1 unit of Prod 1, process to the end 2 units of Prod 1 are created instead of 1. This is due to the WO for Prod 3 not having a `next_work_order_id`. Therefore, `record_production` adds an extra quantity at: ``` production_move.quantity_done += self.qty_producing ``` To prevent this, we set as `next_work_order_id` of the BOM of Prod 3 the WO of Prod 1. Closes #19527 opw-1817398 opw-1883693 --- addons/mrp/models/mrp_production.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 5e3bb3a91bf..cfc80e4415d 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -435,10 +435,16 @@ class MrpProduction(models.Model): @api.multi def _generate_workorders(self, exploded_boms): workorders = self.env['mrp.workorder'] + original_one = False for bom, bom_data in exploded_boms: # If the routing of the parent BoM and phantom BoM are the same, don't recreate work orders, but use one master routing if bom.routing_id.id and (not bom_data['parent_line'] or bom_data['parent_line'].bom_id.routing_id.id != bom.routing_id.id): - workorders += self._workorders_create(bom, bom_data) + temp_workorders = self._workorders_create(bom, bom_data) + workorders += temp_workorders + if temp_workorders: # In order to avoid two "ending work orders" + if original_one: + temp_workorders[-1].next_work_order_id = original_one + original_one = temp_workorders[0] return workorders def _workorders_create(self, bom, bom_data):