Browse Source

Merge branch 'dreispt-8.0-fix-name-search-domain' into 8.0

pull/484/head
Yannick Vaucher 8 years ago
parent
commit
72f375ac68
  1. 2
      base_name_search_improved/__openerp__.py
  2. 15
      base_name_search_improved/models/ir_model.py
  3. 10
      base_name_search_improved/tests/test_name_search.py

2
base_name_search_improved/__openerp__.py

@ -4,7 +4,7 @@
{ {
'name': 'Improved Name Search', 'name': 'Improved Name Search',
'summary': 'Friendlier search when typing in relation fields', 'summary': 'Friendlier search when typing in relation fields',
'version': '8.0.1.0.0',
'version': '8.0.1.0.1',
'category': 'Uncategorized', 'category': 'Uncategorized',
'website': 'https://odoo-community.org/', 'website': 'https://odoo-community.org/',
'author': 'Daniel Reis, Odoo Community Association (OCA)', 'author': 'Daniel Reis, Odoo Community Association (OCA)',

15
base_name_search_improved/models/ir_model.py

@ -13,6 +13,7 @@ ALLOWED_OPS = set(['ilike', 'like'])
@tools.ormcache(skiparg=0) @tools.ormcache(skiparg=0)
def _get_rec_names(self): def _get_rec_names(self):
"List of fields to search into"
model = self.env['ir.model'].search( model = self.env['ir.model'].search(
[('model', '=', str(self._model))]) [('model', '=', str(self._model))])
rec_name = [self._rec_name] or [] rec_name = [self._rec_name] or []
@ -48,22 +49,28 @@ class ModelExtended(models.Model):
self, name=name, args=args, operator=operator, limit=limit) self, name=name, args=args, operator=operator, limit=limit)
enabled = self.env.context.get('name_search_extended', True) enabled = self.env.context.get('name_search_extended', True)
# Perform extended name search # 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 # Support a list of fields to search on
all_names = _get_rec_names(self) all_names = _get_rec_names(self)
base_domain = args or []
# Try regular search on each additional search field # Try regular search on each additional search field
for rec_name in all_names[1:]: for rec_name in all_names[1:]:
domain = [(rec_name, operator, name)] 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 # Try ordered word search on each of the search fields
for rec_name in all_names: for rec_name in all_names:
domain = [(rec_name, operator, name.replace(' ', '%'))] 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 # Try unordered word search on each of the search fields
for rec_name in all_names: for rec_name in all_names:
domain = [(rec_name, operator, x) domain = [(rec_name, operator, x)
for x in name.split() if 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 res
return name_search return name_search

10
base_name_search_improved/tests/test_name_search.py

@ -17,12 +17,15 @@ class NameSearchCase(TransactionCase):
self.Partner = self.env['res.partner'] self.Partner = self.env['res.partner']
self.partner1 = self.Partner.create( self.partner1 = self.Partner.create(
{'name': 'Luigi Verconti', {'name': 'Luigi Verconti',
'customer': True,
'phone': '+351 555 777 333'}) 'phone': '+351 555 777 333'})
self.partner2 = self.Partner.create( self.partner2 = self.Partner.create(
{'name': 'Ken Shabby', {'name': 'Ken Shabby',
'customer': True,
'phone': '+351 555 333 777'}) 'phone': '+351 555 333 777'})
self.partner3 = self.Partner.create( self.partner3 = self.Partner.create(
{'name': 'Johann Gambolputty of Ulm', {'name': 'Johann Gambolputty of Ulm',
'supplier': True,
'phone': '+351 777 333 555'}) 'phone': '+351 777 333 555'})
def test_RelevanceOrderedResults(self): def test_RelevanceOrderedResults(self):
@ -42,3 +45,10 @@ class NameSearchCase(TransactionCase):
"""Must Match All Words""" """Must Match All Words"""
res = self.Partner.name_search('ulm 555 777') res = self.Partner.name_search('ulm 555 777')
self.assertFalse(res) 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)
Loading…
Cancel
Save