[FIX] product: name search not ilike

- Create a product named 'toto'
- Perform a call to `name_search`:
  `self.env['product.product'].name_search('pouet', [], 'not ilike')`

Product 'toto' doesn't show up in the result list.

The domain should take into account that `default_code` can be `False`.

Note: the bug also occurs if the product is called 'trululu'.

opw-1837957
This commit is contained in:
Nicolas Martinelli
2018-04-26 15:07:01 +02:00
committed by Nicolas Martinelli
parent b4f1e316e6
commit d88c3706df
2 changed files with 15 additions and 1 deletions
+6 -1
View File
@@ -431,7 +431,12 @@ class ProductProduct(models.Model):
limit2 = (limit - len(products)) if limit else False
products += self.search(args + [('name', operator, name), ('id', 'not in', products.ids)], limit=limit2)
elif not products and operator in expression.NEGATIVE_TERM_OPERATORS:
products = self.search(args + ['&', ('default_code', operator, name), ('name', operator, name)], limit=limit)
domain = expression.OR([
['&', ('default_code', operator, name), ('name', operator, name)],
['&', ('default_code', '=', False), ('name', operator, name)],
])
domain = expression.AND([args, domain])
products = self.search(domain, limit=limit)
if not products and operator in positive_operators:
ptrn = re.compile('(\[(.*?)\])')
res = ptrn.search(name)
+9
View File
@@ -40,6 +40,15 @@ class TestVariantsSearch(TransactionCase):
self.assertIn(self.product_shirt_template, search_value,
'Shirt should be found searching L')
def test_name_search(self):
self.product_slip_template = self.env['product.template'].create({
'name': 'Slip',
})
res = self.env['product.product'].name_search('Shirt', [], 'not ilike', None)
res_ids = [r[0] for r in res]
self.assertIn(self.product_slip_template.product_variant_ids.id, res_ids,
'Slip should be found searching \'not ilike\'')
class TestVariants(common.TestProductCommon):