From c6ae7eea039df929ae340d87609a103783fcf726 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Fri, 14 Jun 2019 11:26:14 +0000 Subject: [PATCH] [FIX] stock: do not update moves when writing quantities lower than UoM precision Suppose product 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 a message was posted in chatter, of the form: The done move line has been corrected. P: Quantity : 1000.0 -> 1000.0000000000001 opw 2006831 closes odoo/odoo#34124 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_move_line.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 870de679a38..d1e121df9c2 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -276,7 +276,10 @@ class StockMoveLine(models.Model): # When editing a done move line, the reserved availability of a potential chained move is impacted. Take care of running again `_action_assign` on the concerned moves. next_moves = self.env['stock.move'] if updates or 'qty_done' in vals: - for ml in self.filtered(lambda ml: ml.move_id.state == 'done' and ml.product_id.type == 'product'): + mls = self.filtered(lambda ml: ml.move_id.state == 'done' and ml.product_id.type == 'product') + if not updates: # we can skip those where qty_done is already good up to UoM rounding + mls = mls.filtered(lambda ml: not float_is_zero(ml.qty_done - vals['qty_done'], precision_rounding=ml.product_uom_id.rounding)) + for ml in mls: # undo the original move line qty_done_orig = ml.move_id.product_uom._compute_quantity(ml.qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP') in_date = Quant._update_available_quantity(ml.product_id, ml.location_dest_id, -qty_done_orig, lot_id=ml.lot_id,