[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 <amoyaux@users.noreply.github.com>
This commit is contained in:
William Henrotin
2019-03-19 15:18:27 +00:00
parent 04370bff18
commit 9c53a141dc
2 changed files with 8 additions and 0 deletions
@@ -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
+3
View File
@@ -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()