diff --git a/__init__.py b/__init__.py
index 05c4fa7..d471fe4 100644
--- a/__init__.py
+++ b/__init__.py
@@ -11,7 +11,6 @@ def register():
party.PartyIdentifier,
party.Address,
country.Subdivision,
- country.City,
module='account_co_co', type_='model')
Pool.register(
module='account_co_co', type_='wizard')
diff --git a/country.py b/country.py
index 903aef6..d195217 100644
--- a/country.py
+++ b/country.py
@@ -6,7 +6,7 @@ from trytond.pyson import Eval
from trytond.transaction import Transaction
-__all__ = ['Subdivision', 'City']
+__all__ = ['Subdivision']
@@ -17,39 +17,6 @@ class Subdivision(ModelSQL, ModelView):
__metaclass__ = PoolMeta
__name__ = 'country.subdivision'
- city = fields.One2Many('country.city', 'subdivision', 'Citys')
dane_code = fields.Char('Codigo Dane',
help="Codigo Dane, usado en Colombia"
)
-
-
-class City(DeactivableMixin, ModelSQL, ModelView):
- "City"
- __name__ = 'country.city'
- subdivision = fields.Many2One('country.subdivision', 'Subdivision',
- required=True, select=True,
- help="The suddivision where this City is.")
- name = fields.Char('Name', required=True, select=True, translate=True,
- help="The main identifier of the City.")
- code = fields.Char('Code', required=True, select=True,
- help="The ISO code of the City.")
- dane_code = fields.Char('Codigo Dane',
- help="Codigo Dane, usado en Colombia"
- )
-
- @classmethod
- def __setup__(cls):
- super(City, cls).__setup__()
- cls._order.insert(0, ('code', 'ASC'))
-
- @classmethod
- def __register__(cls, module_name):
- pool = Pool()
- Data = pool.get('ir.model.data')
- data = Data.__table__()
- cursor = Transaction().connection.cursor()
-
- super().__register__(module_name)
-
- cursor.execute(*data.delete(where=(data.module == 'subdivision')
- & (data.model == cls.__name__)))
diff --git a/party.py b/party.py
index 869878a..875324b 100644
--- a/party.py
+++ b/party.py
@@ -298,11 +298,36 @@ class Address(ModelSQL, ModelView):
__metaclass__ = PoolMeta
__name__ = 'party.address'
- citys = fields.Many2One("country.city",
+ subdivision_city = fields.Many2One("country.subdivision",
'City',
domain=[
- ('subdivision', '=', Eval('subdivision', 0))],
- depends=['subdivision']
- )
-
-
+ ('country', '=', Eval('country', -1)),
+ ('parent', '=', Eval('subdivision', -1)),
+ ('type', '=', 'city')
+ ],
+ depends=['country', 'subdivision', 'city'],
+ )
+
+
+ @fields.depends('subdivision', 'subdivision_city', 'country')
+ def on_change_country(self):
+ super(Address, self).on_change_country()
+ if (self.subdivision_city
+ and self.subdivision_city.parent != self.subdivision):
+ self.subdivision_city = None
+
+ @fields.depends('subdivision', 'subdivision_city')
+ def on_change_subdivision(self):
+ if hasattr(super(Address, self), 'on_change_subdivision'):
+ super(Address, self).on_change_subdivision()
+ if (self.subdivision_city
+ and self.subdivision_city.parent != self.subdivision):
+ self.subdivision_city = None
+
+
+ @fields.depends('city', 'subdivision_city')
+ def on_change_subdivision_city(self):
+ if self.subdivision_city:
+ self.city = self.subdivision_city.name
+ else:
+ self.city = None
diff --git a/view/address_form.xml b/view/address_form.xml
index c6a8e23..93b4b9c 100644
--- a/view/address_form.xml
+++ b/view/address_form.xml
@@ -3,7 +3,7 @@
-
-
+
+