diff --git a/addons/mrp/models/mrp_abstract_workorder.py b/addons/mrp/models/mrp_abstract_workorder.py index b767d05f258..9d4667cf542 100644 --- a/addons/mrp/models/mrp_abstract_workorder.py +++ b/addons/mrp/models/mrp_abstract_workorder.py @@ -249,6 +249,11 @@ class MrpAbstractWorkorderLine(models.AbstractModel): if self.product_id.tracking == 'serial': self.qty_done = 1 + @api.onchange('product_id') + def _onchange_product_id(self): + if self.product_id and not self.move_id: + self.product_uom_id = self.product_id.uom_id + @api.onchange('qty_done') def _onchange_qty_done(self): """ When the user is encoding a produce line for a tracked product, we apply some logic to diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 57bfca18456..438bff2a52e 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -706,6 +706,9 @@ class TestMrpOrder(TestMrpCommon): self.assertEqual(len(produce_form.workorder_line_ids._records), 2, 'Update the produce quantity should change the components quantity.') self.assertEqual(sum([x['qty_done'] for x in produce_form.workorder_line_ids._records]), 5, 'Update the produce quantity should change the components quantity.') self.assertEqual(sum([x['qty_reserved'] for x in produce_form.workorder_line_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.') + # try adding another product that doesn't belong to the BoM + with produce_form.workorder_line_ids.new() as line: + line.product_id = self.product_4 produce_wizard = produce_form.save() produce_wizard.do_produce()