From 5e08aa3def67d40bce39b2d95760c3221801e3dd Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Tue, 8 Sep 2020 08:15:20 +0000 Subject: [PATCH] [FIX] stock: impossible to merge quants with different in_date When there are no conflict the same quant is used, even of in_date is different. During _update_available_quantity https://github.com/odoo/odoo/blob/12.0/addons/stock/models/stock_quant.py#L209, Odoo use an existing quants without worring in_date (and use min()). Indeed During _gather in_date is not used to find quant (only used to use in ORDER BY) https://github.com/odoo/odoo/blob/12.0/addons/stock/models/stock_quant.py#L111. It sould be logical to don't group by in_date during merge quants. Have two quants with same product_id, location_id, company_id, lot_id, package_id, owner_id but with different in_date. Try to merge quants --> issue quants is not merge closes odoo/odoo#57224 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_quant.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 )