[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
This commit is contained in:
clesgow
2023-07-04 15:18:15 +02:00
parent bff6356585
commit 0b88e0fa1a
+1
View File
@@ -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: