From 365d6a888dbb0b6b7829f6ea1f7dc70adf724ecf Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 1 Feb 2017 16:08:45 +0100 Subject: [PATCH] [FIX] stock: correctly compute custom search method The search on qty_available was refactored twice: - b9853db8 to split the method - a989680b to remove the eval operator At b9853db8 the order of evaluation introduced a bug so that the domain ('qty_available', '=' 10.0) was evaluated if product[qty_available] = 10.0: which crashed (`=` instead of `==`). Before b9853db8, this code did not crash as the operator was converted via if operator == '=': operator = '==' which is no longer executed after the split a989680b replaced the eval by a dictionnary that replaced the eval error by a KeyError when searching with `=` operator. This commit changes several things: - replace the `operator in ('==', '>=', '<=')` as this was evaluated before the operator replacement code mentionned above - remove the replacement code as no longer justified since a989680b - replace the OPERATOR key `==` to always match given key --- addons/stock/models/product.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 5203c44b644..8c9e5246aaf 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -12,7 +12,7 @@ OPERATORS = { '>': py_operator.gt, '<=': py_operator.le, '>=': py_operator.ge, - '==': py_operator.eq, + '=': py_operator.eq, '!=': py_operator.ne } @@ -240,9 +240,6 @@ class Product(models.Model): if not isinstance(value, (float, int)): raise UserError('Invalid domain right operand') - if operator == '=': - operator = '==' - # TODO: Still optimization possible when searching virtual quantities ids = [] for product in self.search([]): @@ -252,7 +249,7 @@ class Product(models.Model): def _search_qty_available(self, operator, value): # TDE FIXME: should probably clean the search methods - if value == 0.0 and operator in ('==', '>=', '<='): + if value == 0.0 and operator in ('=', '>=', '<='): return self._search_product_quantity(operator, value, 'qty_available') product_ids = self._search_qty_available_new(operator, value, self._context.get('lot_id'), self._context.get('owner_id'), self._context.get('package_id')) return [('id', 'in', product_ids)]