diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 4312d66bf14..35920f7a88e 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -520,7 +520,7 @@ class StockMove(models.Model): def _update_quantity_done(self, mo): self.ensure_one() - new_qty = mo.product_uom_id._compute_quantity((mo.qty_producing - mo.qty_produced) * self.unit_factor, mo.product_uom_id, rounding_method='HALF-UP') + new_qty = float_round((mo.qty_producing - mo.qty_produced) * self.unit_factor, precision_rounding=self.product_uom.rounding) if not self.is_quantity_done_editable: self.move_line_ids.filtered(lambda ml: ml.state not in ('done', 'cancel')).qty_done = 0 self.move_line_ids = self._set_quantity_done_prepare_vals(new_qty) diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 43b8cad332d..c7dbb524793 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -3078,3 +3078,28 @@ class TestMrpOrder(TestMrpCommon): update_quantity_wizard.change_prod_qty() self.assertEqual(mo.move_raw_ids[0].product_uom_qty, 2) + + def test_update_qty_to_consume_of_component(self): + """ + The UoM of the finished product has a rounding precision equal to 1.0 + and the UoM of the component has a decimal one. When the producing qty + is set, an onchange autocomplete the consumed quantity of the component. + Then, when updating the 'to consume' quantity of the components, their + consumed quantity is updated again. The test ensures that this update + respects the rounding precisions + """ + self.uom_dozen.rounding = 1 + self.bom_4.product_uom_id = self.uom_dozen + + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = self.bom_4 + mo = mo_form.save() + mo.action_confirm() + + mo.action_toggle_is_locked() + with Form(mo) as mo_form: + mo_form.qty_producing = 1 + with mo_form.move_raw_ids.edit(0) as raw: + raw.product_uom_qty = 1.25 + + self.assertEqual(mo.move_raw_ids.quantity_done, 1.25)