[FIX] res.country name_search
* also returns name-matched countries when a country matches by code * same for states * extract almost-identical implementations of name_search in country and state * remove useless explicit setting of context (also wrong) bzr revid: xmo@openerp.com-20120319162424-aycjfr0rpca3yico
This commit is contained in:
commit
d71340e21a
|
@ -21,6 +21,23 @@
|
||||||
|
|
||||||
from osv import fields, osv
|
from osv import fields, osv
|
||||||
|
|
||||||
|
def location_name_search(self, cr, user, name='', args=None, operator='ilike',
|
||||||
|
context=None, limit=100):
|
||||||
|
if not args:
|
||||||
|
args = []
|
||||||
|
|
||||||
|
ids = []
|
||||||
|
if len(name) == 2:
|
||||||
|
ids = self.search(cr, user, [('code', 'ilike', name)] + args,
|
||||||
|
limit=limit, context=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))
|
||||||
|
|
||||||
|
locations = self.name_get(cr, user, ids, context)
|
||||||
|
return sorted(locations, key=lambda (id, name): ids.index(id))
|
||||||
|
|
||||||
class Country(osv.osv):
|
class Country(osv.osv):
|
||||||
_name = 'res.country'
|
_name = 'res.country'
|
||||||
|
@ -48,23 +65,10 @@ addresses belonging to this country.\n\nYou can use the python-style string pate
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'address_format': "%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s\n%(country_name)s",
|
'address_format': "%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s\n%(country_name)s",
|
||||||
}
|
}
|
||||||
|
|
||||||
def name_search(self, cr, user, name='', args=None, operator='ilike',
|
|
||||||
context=None, limit=100):
|
|
||||||
if not args:
|
|
||||||
args=[]
|
|
||||||
if not context:
|
|
||||||
context={}
|
|
||||||
ids = False
|
|
||||||
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)
|
|
||||||
_order='name'
|
_order='name'
|
||||||
|
|
||||||
|
name_search = location_name_search
|
||||||
|
|
||||||
def create(self, cursor, user, vals, context=None):
|
def create(self, cursor, user, vals, context=None):
|
||||||
if 'code' in vals:
|
if 'code' in vals:
|
||||||
vals['code'] = vals['code'].upper()
|
vals['code'] = vals['code'].upper()
|
||||||
|
@ -77,8 +81,6 @@ addresses belonging to this country.\n\nYou can use the python-style string pate
|
||||||
return super(Country, self).write(cursor, user, ids, vals,
|
return super(Country, self).write(cursor, user, ids, vals,
|
||||||
context=context)
|
context=context)
|
||||||
|
|
||||||
Country()
|
|
||||||
|
|
||||||
|
|
||||||
class CountryState(osv.osv):
|
class CountryState(osv.osv):
|
||||||
_description="Country state"
|
_description="Country state"
|
||||||
|
@ -90,23 +92,9 @@ class CountryState(osv.osv):
|
||||||
'code': fields.char('State Code', size=3,
|
'code': fields.char('State Code', size=3,
|
||||||
help='The state code in three chars.\n', required=True),
|
help='The state code in three chars.\n', required=True),
|
||||||
}
|
}
|
||||||
def name_search(self, cr, user, name='', args=None, operator='ilike',
|
|
||||||
context=None, limit=100):
|
|
||||||
if not args:
|
|
||||||
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,
|
|
||||||
limit=limit, context=context)
|
|
||||||
return self.name_get(cr, user, ids, context)
|
|
||||||
|
|
||||||
_order = 'code'
|
_order = 'code'
|
||||||
CountryState()
|
|
||||||
|
|
||||||
|
|
||||||
|
name_search = location_name_search
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue