From d813873f6c841feea361a9e4f761a9324ff7c956 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Fri, 15 Nov 2019 14:03:10 +0000 Subject: [PATCH] [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: Arnold Moyaux --- addons/mrp/models/mrp_abstract_workorder.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/mrp/models/mrp_abstract_workorder.py b/addons/mrp/models/mrp_abstract_workorder.py index 3e535d3d2a6..1af07bc81cf 100644 --- a/addons/mrp/models/mrp_abstract_workorder.py +++ b/addons/mrp/models/mrp_abstract_workorder.py @@ -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,