[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
This commit is contained in:
Martin Trigaux
2017-02-01 16:09:10 +01:00
parent a28405e469
commit 365d6a888d
+2 -5
View File
@@ -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)]