[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) <whe@odoo.com>
Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2022-09-20 11:33:59 +02:00
parent 6881472d2f
commit 3b6f51d9e2
2 changed files with 36 additions and 1 deletions
+1 -1
View File
@@ -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() \
+35
View File
@@ -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)