trytond-country_zip/address.py

41 lines
1.3 KiB
Python
Raw Normal View History

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'
@staticmethod
def default_country():
Configuration = Pool().get('party.configuration')
config = Configuration(1)
if config.default_country:
return config.default_country.id
def get_subdivision_country(self):
2012-10-09 08:52:39 +02:00
Zip = Pool().get('country.zip')
if self.zip and self.country:
zips = Zip.search([
('zip', '=', self.zip),
('subdivision.country', '=', self.country.id),
], limit=1)
if zips:
zip_, = zips
2015-08-24 15:24:08 +02:00
self.city = zip_.city
if zip_.subdivision:
self.subdivision = zip_.subdivision
@fields.depends('zip', 'country', 'city', 'subdivision')
def on_change_zip(self):
return self.get_subdivision_country()
@fields.depends('zip', 'country', 'city', 'subdivision')
def on_change_country(self):
return self.get_subdivision_country()