[FIX] mrp: wrong consumption warning lines

To reproduce:
1. Create an MO of Product with BOM
2. Manually set qty for a component
3. Produce all

Issue:
Two consumtion warning lines are shown, and numbers are wrong

Part-of: odoo/odoo#140753
This commit is contained in:
yhu-odoo
2023-11-07 17:57:16 +00:00
parent e4b66668e0
commit 71f77ba67c
2 changed files with 7 additions and 5 deletions
+5 -3
View File
@@ -1518,11 +1518,13 @@ class MrpProduction(models.Model):
for move in order.move_raw_ids:
quantity = move.product_uom._compute_quantity(move.quantity, move.product_id.uom_id)
rounding = move.product_id.uom_id.rounding
if not (move.product_id in expected_qty_by_product or float_is_zero(quantity, precision_rounding=rounding)) or not move.picked:
issues.append((order, move.product_id, quantity, 0.0))
# extra lines with non-zero qty picked
if move.product_id not in expected_qty_by_product and move.picked and not float_is_zero(quantity, precision_rounding=rounding):
issues.append((order, move.product_id, 0.0, quantity))
continue
done_qty_by_product[move.product_id] += quantity
done_qty_by_product[move.product_id] += quantity if move.picked else 0.0
# origin lines from bom with different qty
for product, qty_to_consume in expected_qty_by_product.items():
quantity = done_qty_by_product.get(product, 0.0)
if float_compare(qty_to_consume, quantity, precision_rounding=product.uom_id.rounding) != 0:
+2 -2
View File
@@ -3566,9 +3566,9 @@ class TestMrpOrder(TestMrpCommon):
action = mo.button_mark_done()
consumption_warning = Form(self.env['mrp.consumption.warning'].with_context(**action['context'])).save()
self.assertEqual(len(consumption_warning.mrp_consumption_warning_line_ids), 2)
self.assertEqual(len(consumption_warning.mrp_consumption_warning_line_ids), 1)
self.assertEqual(consumption_warning.mrp_consumption_warning_line_ids[0].product_consumed_qty_uom, 0)
self.assertEqual(consumption_warning.mrp_consumption_warning_line_ids[0].product_expected_qty_uom, 0)
self.assertEqual(consumption_warning.mrp_consumption_warning_line_ids[0].product_expected_qty_uom, 1)
# Force the warning
consumption_warning.action_confirm()
self.assertEqual(mo.state, 'done')