Replace default_prefix_zip with default_country and no longer use a prefix in zips.
This commit is contained in:
parent
924aa07df1
commit
23d2c5f33c
31
address.py
31
address.py
|
@ -18,29 +18,42 @@ class Address:
|
|||
super(Address, cls).__setup__()
|
||||
if cls.zip.on_change is None:
|
||||
cls.zip.on_change = []
|
||||
for field in ('zip', 'city', 'subdivision', 'country'):
|
||||
for field in ('zip', 'country'):
|
||||
if not field in cls.zip.on_change:
|
||||
cls.zip.on_change.append(field)
|
||||
if cls.country.on_change is None:
|
||||
cls.country.on_change = []
|
||||
for field in ('zip', 'country'):
|
||||
if not field in cls.country.on_change:
|
||||
cls.country.on_change.append(field)
|
||||
|
||||
@staticmethod
|
||||
def default_zip():
|
||||
def default_country():
|
||||
Configuration = Pool().get('party.configuration')
|
||||
config = Configuration(1)
|
||||
if config.default_prefix_zip:
|
||||
return config.default_prefix_zip
|
||||
if config.default_country:
|
||||
return config.default_country.id
|
||||
|
||||
def on_change_zip(self):
|
||||
def get_subdivision_country(self):
|
||||
res = {}
|
||||
Zip = Pool().get('country.zip')
|
||||
Subdivision = Pool().get('country.subdivision')
|
||||
|
||||
if self.zip:
|
||||
zips = Zip.search([('zip', '=', self.zip)])
|
||||
if self.zip and self.country:
|
||||
zips = Zip.search([
|
||||
('zip', '=', self.zip),
|
||||
('subdivision.country', '=', self.country.id),
|
||||
])
|
||||
if zips:
|
||||
zip_ = zips[0]
|
||||
res['city'] = zip_.city
|
||||
if zip_.subdivision:
|
||||
res['subdivision'] = zip_.subdivision.id
|
||||
res['country'] = (zip_.subdivision.country.id
|
||||
if zip_.subdivision.country else None)
|
||||
return res
|
||||
|
||||
def on_change_zip(self):
|
||||
return self.get_subdivision_country()
|
||||
|
||||
def on_change_country(self):
|
||||
return self.get_subdivision_country()
|
||||
|
||||
|
|
|
@ -10,5 +10,5 @@ __metaclass__ = PoolMeta
|
|||
|
||||
class Configuration:
|
||||
__name__ = 'party.configuration'
|
||||
default_prefix_zip = fields.Property(
|
||||
fields.Char('Prefix Zip', help='Default prefix country (uppercase).'))
|
||||
default_country = fields.Property(fields.Many2One('country.country',
|
||||
'Default Country'))
|
||||
|
|
|
@ -7,16 +7,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
<field name="model">party.configuration</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="party.party_configuration_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='party_lang']" position="after">
|
||||
<label name="default_prefix_zip"/>
|
||||
<field name="default_prefix_zip"/>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
<field name="name">party_configuration_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Loading…
Reference in New Issue