From 7b90ebbcb59173438535e8b99fd6364301ff416f Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Wed, 6 Jul 2016 13:56:36 +0100 Subject: [PATCH 1/3] Test if additional domain is honored --- base_name_search_improved/tests/test_name_search.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/base_name_search_improved/tests/test_name_search.py b/base_name_search_improved/tests/test_name_search.py index 408db3eb5..72dd9933c 100644 --- a/base_name_search_improved/tests/test_name_search.py +++ b/base_name_search_improved/tests/test_name_search.py @@ -17,12 +17,15 @@ class NameSearchCase(TransactionCase): self.Partner = self.env['res.partner'] self.partner1 = self.Partner.create( {'name': 'Luigi Verconti', + 'customer': True, 'phone': '+351 555 777 333'}) self.partner2 = self.Partner.create( {'name': 'Ken Shabby', + 'customer': True, 'phone': '+351 555 333 777'}) self.partner3 = self.Partner.create( {'name': 'Johann Gambolputty of Ulm', + 'supplier': True, 'phone': '+351 777 333 555'}) def test_RelevanceOrderedResults(self): @@ -42,3 +45,10 @@ class NameSearchCase(TransactionCase): """Must Match All Words""" res = self.Partner.name_search('ulm 555 777') self.assertFalse(res) + + def test_MustHonorDomain(self): + """Must also honor a provided Domain""" + res = self.Partner.name_search('+351', args=[('supplier', '=', True)]) + gambulputty = self.partner3.id + self.assertEqual(len(res), 1) + self.assertEqual(res[0][0], gambulputty) From eb5e50a6a0060e065747694b616d1cb22a4404b9 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Wed, 6 Jul 2016 14:50:37 +0100 Subject: [PATCH 2/3] [FIX] Honor name_search additional domain --- base_name_search_improved/models/ir_model.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/base_name_search_improved/models/ir_model.py b/base_name_search_improved/models/ir_model.py index 66b00b3ea..2b0223a1a 100644 --- a/base_name_search_improved/models/ir_model.py +++ b/base_name_search_improved/models/ir_model.py @@ -13,6 +13,7 @@ ALLOWED_OPS = set(['ilike', 'like']) @tools.ormcache(skiparg=0) def _get_rec_names(self): + "List of fields to search into" model = self.env['ir.model'].search( [('model', '=', str(self._model))]) rec_name = [self._rec_name] or [] @@ -51,19 +52,23 @@ class ModelExtended(models.Model): if enabled and operator in ALLOWED_OPS: # Support a list of fields to search on all_names = _get_rec_names(self) + base_domain = args or [] # Try regular search on each additional search field for rec_name in all_names[1:]: domain = [(rec_name, operator, name)] - res = _extend_name_results(self, domain, res, limit) + res = _extend_name_results( + self, base_domain + domain, res, limit) # Try ordered word search on each of the search fields for rec_name in all_names: domain = [(rec_name, operator, name.replace(' ', '%'))] - res = _extend_name_results(self, domain, res, limit) + res = _extend_name_results( + self, base_domain + domain, res, limit) # Try unordered word search on each of the search fields for rec_name in all_names: domain = [(rec_name, operator, x) for x in name.split() if x] - res = _extend_name_results(self, domain, res, limit) + res = _extend_name_results( + self, base_domain + domain, res, limit) return res return name_search From 4ce9c58d9f6e99b2715ebfeeb12af89b2c3ed2f2 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Wed, 6 Jul 2016 23:54:01 +0100 Subject: [PATCH 3/3] Do not search on empty string. Fixes #467 --- base_name_search_improved/models/ir_model.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base_name_search_improved/models/ir_model.py b/base_name_search_improved/models/ir_model.py index 2b0223a1a..cea0dd3c9 100644 --- a/base_name_search_improved/models/ir_model.py +++ b/base_name_search_improved/models/ir_model.py @@ -49,7 +49,9 @@ class ModelExtended(models.Model): self, name=name, args=args, operator=operator, limit=limit) enabled = self.env.context.get('name_search_extended', True) # Perform extended name search - if enabled and operator in ALLOWED_OPS: + # Note: Empty name causes error on + # Customer->More->Portal Access Management + if name and enabled and operator in ALLOWED_OPS: # Support a list of fields to search on all_names = _get_rec_names(self) base_domain = args or []