From 3b6f51d9e2c69a0453629b65057ddebe3966ffa8 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Wed, 31 Aug 2022 09:55:24 +0000 Subject: [PATCH] [FIX] mrp: use rounding when updating qty with 'change.production.qty' Current behavior: When updating the quantity of a MO after it has been confirmed, there was no rounding applied on the move_raw. Steps to reproduce: - Create a new UoM A for units, with a ratio of 250 and a rounding precision of 1 - Create a BoM for 250 quantity of product A, that use 1 quantity of product B with UoM A. - Create a MO for product A, and confirm it. - Change the quantity to product by clicking on the quantity, enter any value above 250 (e.g. 275) - The quantity for product B should is not correct (should be 2) opw-2964561 closes odoo/odoo#100523 X-original-commit: fdea8f8bbb865fb711d470053891545c8f627018 Signed-off-by: William Henrotin (whe) Signed-off-by: Engels Robin (roen) --- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/tests/test_order.py | 35 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index b491218d69b..eba51807078 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1056,7 +1056,7 @@ class MrpProduction(models.Model): procurements = [] for move in self.move_raw_ids.filtered(lambda m: m.state not in ('done', 'cancel')): old_qty = move.product_uom_qty - new_qty = old_qty * factor + new_qty = float_round(old_qty * factor, precision_rounding=move.product_uom.rounding, rounding_method='UP') if new_qty > 0: move.write({'product_uom_qty': new_qty}) if move._should_bypass_reservation() \ diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 07cac7c2d4a..43b8cad332d 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -3043,3 +3043,38 @@ class TestMrpOrder(TestMrpCommon): 'product_id': self.bom_1.product_id.id, }) self.assertEqual(order.bom_id, self.bom_1) + + def test_move_raw_uom_rounding(self): + """Test that the correct rouding is applied on move_raw in + manufacturing orders""" + + self.box250 = self.env['uom.uom'].create({ + 'name': 'box250', + 'category_id': self.env.ref('uom.product_uom_categ_unit').id, + 'ratio': 250.0, + 'uom_type': 'bigger', + 'rounding': 1.0, + }) + + test_bom = self.env['mrp.bom'].create({ + 'product_tmpl_id': self.product_7_template.id, + 'product_uom_id': self.uom_unit.id, + 'product_qty': 250.0, + 'type': 'normal', + 'bom_line_ids': [ + (0, 0, {'product_id': self.product_2.id, 'product_qty': 1.0, 'product_uom_id': self.box250.id}), + ] + }) + + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = test_bom + mo = mo_form.save() + mo.action_confirm() + + update_quantity_wizard = self.env['change.production.qty'].create({ + 'mo_id': mo.id, + 'product_qty': 300, + }) + update_quantity_wizard.change_prod_qty() + + self.assertEqual(mo.move_raw_ids[0].product_uom_qty, 2)