From 71f77ba67c2f2cc30360a3459b021219ea3c6e9f Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Thu, 2 Nov 2023 16:35:19 +0100 Subject: [PATCH] [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 --- addons/mrp/models/mrp_production.py | 8 +++++--- addons/mrp/tests/test_order.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index e7e3f328a5d..a94288c40df 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -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: diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 2b19c1f3923..a3a98b1b546 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -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')