From d0fc2ecfaa56e10ae339cbb9c6ec0a4045f3d499 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Thu, 19 Mar 2020 09:15:30 +0000 Subject: [PATCH] [FIX] stock: unlink zero quants If you create a quant through the inventory mode of the list view and you don't set a quantity, the quantity is null and the quant isn't unlinked by _unlink_zero_quants. Also consider null quantity as 0. We don't have the issue for the reserved_quantity field since this one is not nullable. closes odoo/odoo#48005 X-original-commit: 08e428458aa545b3602c56b6866a447126cf8825 Signed-off-by: Simon Lejeune (sle) --- addons/stock/models/stock_quant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index f819e85ad84..ed914734021 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -507,7 +507,7 @@ class StockQuant(models.Model): """ precision_digits = max(6, self.sudo().env.ref('product.decimal_product_uom').digits * 2) # Use a select instead of ORM search for UoM robustness. - query = """SELECT id FROM stock_quant WHERE round(quantity::numeric, %s) = 0 AND round(reserved_quantity::numeric, %s) = 0;""" + query = """SELECT id FROM stock_quant WHERE (round(quantity::numeric, %s) = 0 OR quantity IS NULL) AND round(reserved_quantity::numeric, %s) = 0;""" params = (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()])