From a419272f520c6edad51f017cf8a644a49183b3f7 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Mon, 3 May 2021 11:52:56 +0000 Subject: [PATCH] [FIX] stock: don't auto remove 0 quant with user Before this commit, when quants where automatically unlinked, all empty quants were took. Now, quants with a defined `user_id` will not be unlinked because they can legitimately be to 0 and we should wait inventory was processed before empty quants were unlinked (as once the inventory is processed, the `user_id` on quant is removed). closes odoo/odoo#70275 X-original-commit: 7c5143e95ef1fcceafe5e331c3e8649e08666ae7 Signed-off-by: Arnold Moyaux Signed-off-by: Steve Van Essche --- addons/stock/models/stock_quant.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 48f74f97079..829a796270e 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -626,7 +626,8 @@ class StockQuant(models.Model): # Use a select instead of ORM search for UoM robustness. query = """SELECT id FROM stock_quant WHERE (round(quantity::numeric, %s) = 0 OR quantity IS NULL) AND round(reserved_quantity::numeric, %s) = 0 - AND (round(inventory_quantity::numeric, %s) = 0 OR inventory_quantity IS NULL);""" + AND (round(inventory_quantity::numeric, %s) = 0 OR inventory_quantity IS NULL) + AND user_id IS NULL;""" params = (precision_digits, precision_digits, precision_digits) self.env.cr.execute(query, params) quant_ids = self.env['stock.quant'].browse([quant['id'] for quant in self.env.cr.dictfetchall()])