2018-01-23 17:18:06 +01:00
|
|
|
# This file is part country_zip module for Tryton. The COPYRIGHT file at the
|
|
|
|
# top level of this repository contains the full copyright notices and license
|
|
|
|
# terms.
|
2014-07-10 10:49:07 +02:00
|
|
|
from trytond.model import fields
|
2012-10-09 11:01:32 +02:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2012-06-12 10:49:05 +02:00
|
|
|
|
2012-10-09 08:52:39 +02:00
|
|
|
__all__ = ['Address']
|
|
|
|
|
2012-10-09 11:01:32 +02:00
|
|
|
|
2018-09-15 18:09:06 +02:00
|
|
|
class Address(metaclass=PoolMeta):
|
2012-10-09 08:52:39 +02:00
|
|
|
__name__ = 'party.address'
|
2013-10-17 11:47:39 +02:00
|
|
|
|
2013-03-19 15:54:04 +01:00
|
|
|
@staticmethod
|
2013-10-17 18:00:18 +02:00
|
|
|
def default_country():
|
2013-03-19 15:54:04 +01:00
|
|
|
Configuration = Pool().get('party.configuration')
|
|
|
|
config = Configuration(1)
|
2013-10-17 18:00:18 +02:00
|
|
|
if config.default_country:
|
|
|
|
return config.default_country.id
|
2013-03-19 15:54:04 +01:00
|
|
|
|
2013-10-17 18:00:18 +02:00
|
|
|
def get_subdivision_country(self):
|
2012-10-09 08:52:39 +02:00
|
|
|
Zip = Pool().get('country.zip')
|
|
|
|
|
2013-10-17 18:00:18 +02:00
|
|
|
if self.zip and self.country:
|
|
|
|
zips = Zip.search([
|
|
|
|
('zip', '=', self.zip),
|
|
|
|
('subdivision.country', '=', self.country.id),
|
2019-09-16 13:48:16 +02:00
|
|
|
], limit=1)
|
2013-10-17 11:47:39 +02:00
|
|
|
if zips:
|
2015-09-22 10:13:16 +02:00
|
|
|
zip_, = zips
|
2015-08-24 15:24:08 +02:00
|
|
|
self.city = zip_.city
|
2013-10-17 11:47:39 +02:00
|
|
|
if zip_.subdivision:
|
2015-09-22 10:13:16 +02:00
|
|
|
self.subdivision = zip_.subdivision
|
2013-10-17 18:00:18 +02:00
|
|
|
|
2015-09-22 10:13:16 +02:00
|
|
|
@fields.depends('zip', 'country', 'city', 'subdivision')
|
2013-10-17 18:00:18 +02:00
|
|
|
def on_change_zip(self):
|
|
|
|
return self.get_subdivision_country()
|
|
|
|
|
2015-09-22 10:13:16 +02:00
|
|
|
@fields.depends('zip', 'country', 'city', 'subdivision')
|
2013-10-17 18:00:18 +02:00
|
|
|
def on_change_country(self):
|
|
|
|
return self.get_subdivision_country()
|