[FIX] stock: correctly compute custom search method
The search on qty_available was refactored twice: -b9853db8to split the method -a989680bto remove the eval operator Atb9853db8the 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 `==`). Beforeb9853db8, this code did not crash as the operator was converted via if operator == '=': operator = '==' which is no longer executed after the splita989680breplaced 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 sincea989680b- replace the OPERATOR key `==` to always match given key
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user