Skip to content
Snippets Groups Projects
Commit d813873f authored by William Henrotin's avatar William Henrotin
Browse files

[FIX] mrp: convert quantity in product UoM


If a component is used in a production with another unit of measure
than it's one, the created stock move line could not convert the quantity
correctly.
If there is enough quantity in stock, the created move line takes the
quant uom but the quantity in the production ones.
ex: consume 1 dozen, the quantity on the stock move line is 1 unit

This commit always uses the wo line's UoM and quantity to create the
stock move line.

closes odoo/odoo#39222

Signed-off-by: default avatarArnold Moyaux <amoyaux@users.noreply.github.com>
parent 1efe2fc9
Branches
Tags
No related merge requests found
......@@ -418,9 +418,10 @@ class MrpAbstractWorkorderLine(models.AbstractModel):
# reservation is made, so it is still possible to change it afterwards.
for quant in quants:
quantity = quant.quantity - quant.reserved_quantity
quantity = self.product_id.uom_id._compute_quantity(quantity, self.product_uom_id, rounding_method='HALF-UP')
rounding = quant.product_uom_id.rounding
if (float_compare(quant.quantity, 0, precision_rounding=rounding) <= 0 or
float_compare(quantity, 0, precision_rounding=rounding) <= 0):
float_compare(quantity, 0, precision_rounding=self.product_uom_id.rounding) <= 0):
continue
vals = {
'move_id': self.move_id.id,
......@@ -428,7 +429,7 @@ class MrpAbstractWorkorderLine(models.AbstractModel):
'location_id': quant.location_id.id,
'location_dest_id': self.move_id.location_dest_id.id,
'product_uom_qty': 0,
'product_uom_id': quant.product_uom_id.id,
'product_uom_id': self.product_uom_id.id,
'qty_done': min(quantity, self.qty_done),
'lot_produced_ids': self._get_produced_lots(),
}
......@@ -438,10 +439,10 @@ class MrpAbstractWorkorderLine(models.AbstractModel):
vals_list.append(vals)
self.qty_done -= vals['qty_done']
# If all the qty_done is distributed, we can close the loop
if float_compare(self.qty_done, 0, precision_rounding=self.product_uom_id.rounding) <= 0:
if float_compare(self.qty_done, 0, precision_rounding=self.product_id.uom_id.rounding) <= 0:
break
if float_compare(self.qty_done, 0, precision_rounding=self.product_uom_id.rounding) > 0:
if float_compare(self.qty_done, 0, precision_rounding=self.product_id.uom_id.rounding) > 0:
vals = {
'move_id': self.move_id.id,
'product_id': self.product_id.id,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment