[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:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user