odoo/odoo#256005

Created by Bugfix, Djamel Touati (otd)
Closed
label
odoo-dev:19.0-opw-6069371-mrp_plm-prevent-crash-bom-update-eco-revision-otd
head
dff3eabb338e907e01da3223d77562bc5ed6470a
odoo/odoo
19.0 #256005

[FIX] mrp, mrp_plm: prevent crash when updating BoM after ECO revision

Steps to reproduce:
- Create a storable product "P1"
- Create a BoM:
- Component: C1

-> BoM V1 is archived (expected behavior)

Result:
The "Update BoM" button becomes visible in the view and can be clicked:

https://github.com/odoo/enterprise/blob/d1e75bf651ba06ce065afa8e6ca18e6b25e2dfce/mrp_plm/views/mrp_production_views.xml#L32

Problem:
Clicking on "Update BoM" raises the following error:

Record does not exist or has been deleted.
(Record: stock.move(29,), User: 2)

Explanation:
When clicking on "Update BoM", the method action_update_bom calls _link_bom with the new BoM (V2).

https://github.com/odoo/enterprise/blob/96ef7f9eab64c22de4bb63ddb2ca1265d507aff7/mrp_plm/models/mrp_production.py#L78-L79

Before assigning the new BoM and creating the new component moves, the existing moves (linked to component C1) are stored in a variable, to be unlinked later:
https://github.com/odoo/odoo/blob/e831903612efbb21698d911c5b156ecdcdcae531/addons/mrp/models/mrp_production.py#L2163-L2165

Then the new BoM is assigned, which triggers _compute_move_raw_ids. Since this is a real BoM change (V1 → V2) and not a simple recomputation of the same BoM, the existing moves are automatically unlinked.

https://github.com/odoo/odoo/blob/e831903612efbb21698d911c5b156ecdcdcae531/addons/mrp/models/mrp_production.py#L714-L715

After that, _link_bom still tries to unlink the previously stored moves, which no longer exist, and this raises the error.

https://github.com/odoo/odoo/blob/e831903612efbb21698d911c5b156ecdcdcae531/addons/mrp/models/mrp_production.py#L2166

Solution:
Only unlink the moves that still belong to the current BoM in order to avoid trying to delete already removed records.

opw-6069371