From d88c3706dfbe4f77bfcb2bfcc6bd95e7758cd49f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 25 Apr 2018 21:50:19 +0200 Subject: [PATCH] [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 --- addons/product/models/product.py | 7 ++++++- addons/product/tests/test_variants.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 3f50ffef7cb..2dce8e9fa36 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -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) diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py index 7917a0d4a2b..804bbc55c95 100644 --- a/addons/product/tests/test_variants.py +++ b/addons/product/tests/test_variants.py @@ -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):