Skip to content
Snippets Groups Projects
Commit 0a854e59 authored by Touati Djamel (otd)'s avatar Touati Djamel (otd)
Browse files

[FIX] mrp: delete link between BoM lines and OP when changing bom in OP


Steps to reproduce the bug:
- Create a storable product “P1” with BoM
    - Operation: OP1
    - Component: C1, consumed in: OP1

- Navigate to Mrp > Configuration > Operations
- Select OP1 and select another BoM
- return to the BoM of “P1”

Problem:
The BoM line for component "P1" is still linked to OP1,
And a traceback when attempting to duplicate the BoM.

Solution:
Remove the operation from the initial BOM

opw-3429980

closes odoo/odoo#128821

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent c673d9db
No related branches found
No related tags found
No related merge requests found
......@@ -83,3 +83,9 @@ class MrpRoutingWorkcenter(models.Model):
return False
self.ensure_one()
return tuple(self[key] for key in ('name', 'company_id', 'workcenter_id', 'time_mode', 'time_cycle_manual'))
def write(self, values):
if 'bom_id' in values:
filtered_lines = self.bom_id.bom_line_ids.filtered(lambda line: line.operation_id == self)
filtered_lines.operation_id = False
return super().write(values)
......@@ -979,3 +979,26 @@ class TestBoM(TestMrpCommon):
self.assertEqual(p1.qty_available, 5.0)
self.assertEqual(p2.qty_available, 10.0)
self.assertEqual(p3.qty_available, 10.0)
def test_update_bom_in_routing_workcenter(self):
"""
This test checks the behaviour of updating the BoM associated with a routing workcenter,
It verifies that the link between the BOM lines and the operation is correctly deleted.
"""
p1, c1, c2 = self.make_prods(3)
bom = self.env['mrp.bom'].create({
'product_tmpl_id': p1.product_tmpl_id.id,
'product_qty': 1.0,
'bom_line_ids': [(0, 0, {'product_id': c1.id, 'product_qty': 1.0}),
(0, 0, {'product_id': c2.id, 'product_qty': 1.0})],
})
operation = self.env['mrp.routing.workcenter'].create({
'name': 'Operation',
'workcenter_id': self.env.ref('mrp.mrp_workcenter_1').id,
'bom_id': bom.id,
})
bom.bom_line_ids.operation_id = operation
self.assertEqual(operation.bom_id, bom)
operation.bom_id = self.bom_1
self.assertEqual(operation.bom_id, self.bom_1)
self.assertFalse(bom.bom_line_ids.operation_id)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment