Skip to content
Snippets Groups Projects
Commit 587a2996 authored by Adrien Widart (awt)'s avatar Adrien Widart (awt)
Browse files

[FIX] mrp: prevent from merging other products' SM

To reproduce the issue:
1. In Settings, enable:
   - Multi-Routes
2. Unarchive the route MTO
3. Create three storable product P1, P2, P3:
   - P2:
     - With route MTO
4. Create and confirm a MO:
   - Product: P1
   - Components:
     - 1 x P2
     - 1 x P3
     - 1 x P3
5. Set the produced/consumed quantities:
   - For P2, set 1.5
6. Mark the MO as done

Error: an error message is displayed: "Record does not exist or has
been deleted."

In `SM._action_done`, we create some extra moves:
https://github.com/odoo/odoo/blob/e029abe649573350e633999e42ab040c57b8fe4e/addons/stock/models/stock_move.py#L1705-L1710
Because of the exceed quantity on the first components line, we
create a new SM (qty 0.5). There is a difference between both SM:
the `procure_method` (MTO for the initial SM, MTS for the new one).
Because of that difference, when confirming the new SM, we don't
provide any `merge_into` (the `else` block):
https://github.com/odoo/odoo/blob/e029abe649573350e633999e42ab040c57b8fe4e/addons/stock/models/stock_move.py#L1684-L1690
Confirming the new SM leads to the `_merge_moves` method. In this
method, because we didn't provide any `merge_into`, we first try to
get some candidates:
https://github.com/odoo/odoo/blob/e029abe649573350e633999e42ab040c57b8fe4e/addons/stock/models/stock_move.py#L866-L868
And at that point, we will provide with all components SMs:
https://github.com/odoo/odoo/blob/e029abe649573350e633999e42ab040c57b8fe4e/addons/mrp/models/stock_move.py#L494-L497


So, we will also provide the two SM of C02. Therefore, the method
will merge these SMs and unlink the second one. Then, back to the
extra moves creation in `SM._action_done`, the for loop will iterate
on the deleted record, hence the error.

OPW-3454899

closes odoo/odoo#134632

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent 4412e547
Branches
Tags
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment