Add autocomplete on zip and city
issue4004 review9441002
This commit is contained in:
1 parent
725a057ba2
commit
697f24cb5c
2 files changed
+39
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Add autocomplete on zip and city
|
||||
|
||||
Version 3.2.0 - 2014-04-21
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
|
||||
|
||||
+37
@@ -5,6 +5,7 @@ from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.transaction import Transaction
|
||||
from trytond import backend
|
||||
from trytond.pool import Pool
|
||||
|
||||
__all__ = ['Address']
|
||||
|
||||
@@ -66,6 +67,42 @@ class Address(ModelSQL, ModelView):
|
||||
def default_active():
|
||||
return True
|
||||
|
||||
_autocomplete_limit = 100
|
||||
|
||||
def _autocomplete_domain(self):
|
||||
domain = []
|
||||
if self.country:
|
||||
domain.append(('country', '=', self.country.id))
|
||||
if self.subdivision:
|
||||
domain.append(['OR',
|
||||
('subdivision', '=', self.subdivision.id),
|
||||
('subdivision', '=', None),
|
||||
])
|
||||
return domain
|
||||
|
||||
def _autocomplete_search(self, domain, name):
|
||||
pool = Pool()
|
||||
Zip = pool.get('country.zip')
|
||||
if domain:
|
||||
records = Zip.search(domain, limit=self._autocomplete_limit)
|
||||
if len(records) < self._autocomplete_limit:
|
||||
return sorted({getattr(z, 'name') for z in records})
|
||||
return []
|
||||
|
||||
@fields.depends('city', 'country', 'subdivision')
|
||||
def autocomplete_zip(self):
|
||||
domain = self._autocomplete_domain()
|
||||
if self.city:
|
||||
domain.append(('city', 'ilike', '%%%s%%' % self.city))
|
||||
return self._autocomplete_search(domain, 'zip')
|
||||
|
||||
@fields.depends('zip', 'country', 'subdivision')
|
||||
def autocomplete_city(self):
|
||||
domain = self._autocomplete_domain()
|
||||
if self.zip:
|
||||
domain.append(('zip', 'ilike', '%s%%' % self.zip))
|
||||
return self._autocomplete_search(domain, 'city')
|
||||
|
||||
def get_full_address(self, name):
|
||||
full_address = ''
|
||||
if self.name:
|
||||
|
||||
Reference in new issue
Block a user