diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 600ffc35859..f8c95c5db46 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -514,15 +514,17 @@ class StockQuant(models.Model): SELECT min(id) as to_update_quant_id, (array_agg(id ORDER BY id))[2:array_length(array_agg(id), 1)] as to_delete_quant_ids, SUM(reserved_quantity) as reserved_quantity, - SUM(quantity) as quantity + SUM(quantity) as quantity, + MIN(in_date) as in_date FROM stock_quant - GROUP BY product_id, company_id, location_id, lot_id, package_id, owner_id, in_date + GROUP BY product_id, company_id, location_id, lot_id, package_id, owner_id HAVING count(id) > 1 ), _up AS ( UPDATE stock_quant q SET quantity = d.quantity, - reserved_quantity = d.reserved_quantity + reserved_quantity = d.reserved_quantity, + in_date = d.in_date FROM dupes d WHERE d.to_update_quant_id = q.id )