From 9c53a141dcecf9646e8ddba42ffca34b4b593b69 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Tue, 19 Mar 2019 15:18:27 +0000 Subject: [PATCH] [FIX] mrp: missing default uom purpose: on a MO, producing via the 'Produce' wizard give the ability to add any additionnal product into the production. The issue is that the UoM of the new line is empty and so will trigger an error later in the flow. This commit add a new onchange on product_id to ensure the field product_uom_id will be set accordingly closes odoo/odoo#31950 Signed-off-by: Arnold Moyaux --- addons/mrp/models/mrp_abstract_workorder.py | 5 +++++ addons/mrp/tests/test_order.py | 3 +++ 2 files changed, 8 insertions(+) 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()