[FIX] res.country (and res.country.state) name_search so it returns all countries matching even when there's a country matching by code

bzr revid: xmo@openerp.com-20120319161526-txd1eiomjrntgmxi
This commit is contained in:
Xavier Morel 2012-03-19 17:15:26 +01:00
parent e02eab8d97
commit f1bbbaa5f8
1 changed files with 20 additions and 10 deletions

View File

@ -55,14 +55,18 @@ addresses belonging to this country.\n\nYou can use the python-style string pate
args=[]
if not context:
context={}
ids = False
ids = []
if len(name) == 2:
ids = self.search(cr, user, [('code', 'ilike', name)] + args,
limit=limit, context=context)
if not ids:
ids = self.search(cr, user, [('name', operator, name)] + args,
limit=limit, context=context)
return self.name_get(cr, user, ids, context)
search_domain = [('name', operator, name)]
if ids:
search_domain.append(('id', 'not in', ids))
ids.extend(self.search(cr, user, search_domain + args,
limit=limit, context=context))
countries = self.name_get(cr, user, ids, context)
return sorted(countries, key=lambda c: ids.index(c[0]))
_order='name'
def create(self, cursor, user, vals, context=None):
@ -96,12 +100,18 @@ class CountryState(osv.osv):
args = []
if not context:
context = {}
ids = self.search(cr, user, [('code', 'ilike', name)] + args, limit=limit,
context=context)
if not ids:
ids = self.search(cr, user, [('name', operator, name)] + args,
ids = []
if len(name) == 2:
ids = self.search(cr, user, [('code', 'ilike', name)] + args,
limit=limit, context=context)
return self.name_get(cr, user, ids, context)
search_domain = [('name', operator, name)]
if ids:
search_domain.append(('id', 'not in', ids))
ids.extend(self.search(cr, user, search_domain + args,
limit=limit, context=context))
states = self.name_get(cr, user, ids, context)
return sorted(states, key=lambda c: ids.index(c[0]))
_order = 'code'
CountryState()