[REF] use single implementation for name_search of Country and CountryState
bzr revid: xmo@openerp.com-20120319162256-2wcmges2o1gqpb3e
This commit is contained in:
parent
f1bbbaa5f8
commit
35c0c36816
|
@ -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,27 +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 = []
|
|
||||||
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))
|
|
||||||
countries = self.name_get(cr, user, ids, context)
|
|
||||||
return sorted(countries, key=lambda c: ids.index(c[0]))
|
|
||||||
_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()
|
||||||
|
@ -81,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"
|
||||||
|
@ -94,29 +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 = []
|
|
||||||
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))
|
|
||||||
states = self.name_get(cr, user, ids, context)
|
|
||||||
return sorted(states, key=lambda c: ids.index(c[0]))
|
|
||||||
|
|
||||||
_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