From 0b88e0fa1a1b7a438e0c59c4ba0fa7394e4fe48a Mon Sep 17 00:00:00 2001 From: clesgow Date: Thu, 8 Jun 2023 12:09:28 +0000 Subject: [PATCH] [FIX] mrp: unlink workorders from old bom when switching mo's bom Steps to reproduce (Manufacturing app): - Configuration -> Settings -> Activate `Work Orders`. - Products -> Bill of Materials - Create 2 BoM for a single product (e.g. Product A), both with operations. - Operations -> Manufacturing Orders. - Create a MO for Product A and save it. - MO was created using the first BoM and has its operations set in Work Orders. - Update the MO from first to second BoM. - Components are switched but the new operations are added to the old ones in Work Orders. The only way for a workorder to be deleted automatically when updating a manufacturing order is to change its product. There was no check whether an operation was related to another bom or not. As different BoM can have different operations (as well as components), it makes sense to remove operations related to another BoM when switching them. Task-3277166 X-original-commit: 30044e5dc698e3b8822fa7094b34c28c83861d1d Part-of: odoo/odoo#127143 --- addons/mrp/models/mrp_production.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 8e114cf73f9..bb4c303ed30 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -537,6 +537,7 @@ class MrpProduction(models.Model): if production.state != 'draft': continue workorders_list = [Command.link(wo.id) for wo in production.workorder_ids.filtered(lambda wo: not wo.operation_id)] + workorders_list += [Command.delete(wo.id) for wo in production.workorder_ids.filtered(lambda wo: wo.operation_id and wo.operation_id.bom_id != production.bom_id)] if not production.bom_id and not production._origin.product_id: production.workorder_ids = workorders_list if production.product_id != production._origin.product_id: