[FIX] mrp: Quantities of components on MO

Steps to reproduce the bug:

- Install Manufacturing
- Go to General Settings/Inventory and tick Units of Measure
- Create a product P (storable) with UOM kg
- Create a Bill of Material for this product: e.g. 1 kg
- Add a component C with UOM "kg", but in the BOM uses "g"
- Create a MO for P, Mark as todo, Produce
- Click on C to change the quantities (e.g. change the first line to 900 g)
- Add a second line with 0.1 kg (as the uom of C is in kg, you are forced to set in kg)

Bug:
The strict consumption check is raised. It happens because the
lines quantity done are not correctly converted in the same
UoM

opw:2181892

closes odoo/odoo#46103

X-original-commit: e385930f8687fc4051ddd375fe0551dba59a8750
Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
Goffin Simon
2020-02-24 13:18:26 +00:00
committed by Arnold Moyaux
parent eb1207a705
commit fd0937bdc7
+5 -2
View File
@@ -297,8 +297,11 @@ class MrpAbstractWorkorder(models.AbstractModel):
if self.consumption == 'strict':
for move in self.move_raw_ids:
lines = self._workorder_line_ids().filtered(lambda l: l.move_id == move)
qty_done = sum(lines.mapped('qty_done'))
qty_to_consume = sum(lines.mapped('qty_to_consume'))
qty_done = 0.0
qty_to_consume = 0.0
for line in lines:
qty_done += line.product_uom_id._compute_quantity(line.qty_done, line.product_id.uom_id)
qty_to_consume += line.product_uom_id._compute_quantity(line.qty_to_consume, line.product_id.uom_id)
rounding = self.product_uom_id.rounding
if float_compare(qty_done, qty_to_consume, precision_rounding=rounding) != 0:
raise UserError(_('You should consume the quantity of %s defined in the BoM. If you want to consume more or less components, change the consumption setting on the BoM.') % lines[0].product_id.name)