[FIX] mrp: clear component if the BoM change

Steps to reproduce the bug:
- Create a storable product ”P1” with 2 BoM:
    - BoM 1:
        Type: manufacture
        Component: C1
    - BoM 2:
        Type: manufacture
        Component: C2
- Create a MO:
    - Add the product “P1”
    - The BoM 1 is automatically set and the component “C1” is added
    - Save the MO
- Edit The MO:
    - set the BoM 2 instead of BoM 1

Problem:
The component C2 is added, but the component “C1” linked to BoM 1 is
not deleted

To delete the existing lines, we check if the product has changed,
but we do not check if the BoM has changed:
https://github.com/odoo/odoo/blob/16.0/addons/mrp/models/mrp_production.py#L694

Solution:
clear “move_raws” if BoM change.
No need to check if the product has changed to clear component,because
if the product changes, the bom changes too

opw-3069283

closes odoo/odoo#105983

X-original-commit: 916449eb382715f341b05666cfec336e30c5db36
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-11-18 12:58:11 +01:00
parent 44ccc0dd83
commit ccd66d3e18
+1 -1
View File
@@ -691,7 +691,7 @@ class MrpProduction(models.Model):
list_move_raw = [Command.link(move.id) for move in production.move_raw_ids.filtered(lambda m: not m.bom_line_id)]
if not production.bom_id and not production._origin.product_id:
production.move_raw_ids = list_move_raw
if production.product_id != production._origin.product_id:
if production.bom_id != production._origin.bom_id:
production.move_raw_ids = [Command.clear()]
if production.bom_id and production.product_id and production.product_qty > 0:
# keep manual entries