From a5a4b154ee4e4d83f99b35b8899ad406dbee6b12 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Fri, 14 Jun 2019 08:50:32 +0000 Subject: [PATCH] [FIX] stock_account: round quantities to UoM precision when updating moves Have a product P values in FIFO, create an incoming stock move. Suppose P has UoM U with rounding R, and the stock move has quantity Q. Edit the quantity done to be Q + e, with e << R. By the semantic of the UoM rounding, this should mean that no change has been done. However no such check was done, so the move was updated. As a result, this would mess up the valuation of P. opw 2006831 --- addons/stock_account/models/stock.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 23276976ff5..d6f30d301b7 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -88,7 +88,10 @@ class StockMoveLine(models.Model): if 'qty_done' in vals: moves_to_update = {} for move_line in self.filtered(lambda ml: ml.state == 'done' and (ml.move_id._is_in() or ml.move_id._is_out())): - moves_to_update[move_line.move_id] = vals['qty_done'] - move_line.qty_done + rounding = move_line.product_uom_id.rounding + qty_difference = float_round(vals['qty_done'] - move_line.qty_done, precision_rounding=rounding) + if not float_is_zero(qty_difference, precision_rounding=rounding): + moves_to_update[move_line.move_id] = qty_difference for move_id, qty_difference in moves_to_update.items(): move_vals = {}