diff --git a/base_location_nuts/README.rst b/base_location_nuts/README.rst index 4ecb18da6..76fa16b89 100644 --- a/base_location_nuts/README.rst +++ b/base_location_nuts/README.rst @@ -23,7 +23,7 @@ NUTS Regions :target: https://runbot.odoo-community.org/runbot/134/12.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| This module allows to import NUTS locations. @@ -58,7 +58,7 @@ Configuration After installation, you must click at import wizard to populate NUTS items in Odoo database in: -Sales > Configuration > Address Book > Import NUTS 2013 +Contacts > Configuration > Localization > Import NUTS 2013 This wizard will download from Europe RAMON service the metadata to build NUTS in Odoo. Each localization addon (l10n_es_location_nuts, diff --git a/base_location_nuts/__manifest__.py b/base_location_nuts/__manifest__.py index 7c3cad397..d45f00ad2 100644 --- a/base_location_nuts/__manifest__.py +++ b/base_location_nuts/__manifest__.py @@ -6,8 +6,8 @@ { "name": "NUTS Regions", "category": "Localisation/Europe", - "version": "12.0.1.0.0", - "depends": ["contacts",], + "version": "13.0.1.0.0", + "depends": ["contacts"], "data": [ "views/res_country_view.xml", "views/res_partner_nuts_view.xml", @@ -15,7 +15,7 @@ "wizard/nuts_import_view.xml", "security/ir.model.access.csv", ], - "images": ["images/new_fields.png",], + "images": ["images/new_fields.png"], "author": "Tecnativa, " "Agile Business Group, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/partner-contact/", "license": "AGPL-3", diff --git a/base_location_nuts/migrations/12.0.1.0.0/post-migration.py b/base_location_nuts/migrations/12.0.1.0.0/post-migration.py deleted file mode 100644 index 286404924..000000000 --- a/base_location_nuts/migrations/12.0.1.0.0/post-migration.py +++ /dev/null @@ -1,6 +0,0 @@ -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - env["res.partner.nuts"]._parent_store_compute() diff --git a/base_location_nuts/models/res_partner.py b/base_location_nuts/models/res_partner.py index 8eff33523..0ff9018f2 100644 --- a/base_location_nuts/models/res_partner.py +++ b/base_location_nuts/models/res_partner.py @@ -12,16 +12,10 @@ class ResPartner(models.Model): comodel_name="res.partner.nuts", domain=[("level", "=", 1)], string="NUTS L1" ) nuts2_id = fields.Many2one( - comodel_name="res.partner.nuts", - domain=[("level", "=", 2)], - string="NUTS L2", - oldname="region", + comodel_name="res.partner.nuts", domain=[("level", "=", 2)], string="NUTS L2" ) nuts3_id = fields.Many2one( - comodel_name="res.partner.nuts", - domain=[("level", "=", 3)], - string="NUTS L3", - oldname="substate", + comodel_name="res.partner.nuts", domain=[("level", "=", 3)], string="NUTS L3" ) nuts4_id = fields.Many2one( comodel_name="res.partner.nuts", domain=[("level", "=", 4)], string="NUTS L4" @@ -50,9 +44,7 @@ class ResPartner(models.Model): domain_field = "nuts%d_id" % (level + 1) parent_id = self[parent_field].id if parent_id: - result["domain"][domain_field] = [ - ("parent_id", "=", parent_id), - ] + result["domain"][domain_field] = [("parent_id", "=", parent_id)] level += 1 return result @@ -90,13 +82,11 @@ class ResPartner(models.Model): domain[field].append(("level", "=", level)) if self.country_id: nuts1 = self.env["res.partner.nuts"].search( - [("level", "=", 1), ("country_id", "=", self.country_id.id),], limit=1 + [("level", "=", 1), ("country_id", "=", self.country_id.id)], limit=1 ) if self.nuts1_id.id != nuts1.id: self.nuts1_id = nuts1.id - return { - "domain": domain, - } + return {"domain": domain} @api.onchange("state_id") def onchange_state_id_base_location_nuts(self): diff --git a/base_location_nuts/models/res_partner_nuts.py b/base_location_nuts/models/res_partner_nuts.py index 510e7d351..2cbf14f91 100644 --- a/base_location_nuts/models/res_partner_nuts.py +++ b/base_location_nuts/models/res_partner_nuts.py @@ -16,17 +16,12 @@ class ResPartnerNuts(models.Model): level = fields.Integer(required=True) code = fields.Char(required=True) name = fields.Char(required=True, translate=True) - country_id = fields.Many2one( - comodel_name="res.country", string="Country", required=True - ) - state_id = fields.Many2one(comodel_name="res.country.state", string="State") + country_id = fields.Many2one(comodel_name="res.country", required=True) + state_id = fields.Many2one(comodel_name="res.country.state") not_updatable = fields.Boolean() # Parent hierarchy parent_id = fields.Many2one(comodel_name="res.partner.nuts", ondelete="restrict") parent_path = fields.Char(index=True) child_ids = fields.One2many( - comodel_name="res.partner.nuts", - inverse_name="parent_id", - string="Children", - oldname="children", + comodel_name="res.partner.nuts", inverse_name="parent_id", string="Children" ) diff --git a/base_location_nuts/readme/CONFIGURE.rst b/base_location_nuts/readme/CONFIGURE.rst index f8b59fd9c..035a59fe5 100644 --- a/base_location_nuts/readme/CONFIGURE.rst +++ b/base_location_nuts/readme/CONFIGURE.rst @@ -1,6 +1,6 @@ After installation, you must click at import wizard to populate NUTS items in Odoo database in: -Sales > Configuration > Address Book > Import NUTS 2013 +Contacts > Configuration > Localization > Import NUTS 2013 This wizard will download from Europe RAMON service the metadata to build NUTS in Odoo. Each localization addon (l10n_es_location_nuts, diff --git a/base_location_nuts/readme/CONTRIBUTORS.rst b/base_location_nuts/readme/CONTRIBUTORS.rst index 9140ccea6..1a8ae4ba1 100644 --- a/base_location_nuts/readme/CONTRIBUTORS.rst +++ b/base_location_nuts/readme/CONTRIBUTORS.rst @@ -4,3 +4,4 @@ * David Vidal * Simone Rubino * Alexandre Díaz +* Andrea Stirpe diff --git a/base_location_nuts/readme/INSTALL.rst b/base_location_nuts/readme/INSTALL.rst index d0d761c31..c4ba7bb4a 100644 --- a/base_location_nuts/readme/INSTALL.rst +++ b/base_location_nuts/readme/INSTALL.rst @@ -3,3 +3,4 @@ NUTS with states defined by each localization addon, for example: * l10n_es_location_nuts : Spanish Provinces (NUTS level 4) related to Partner State * l10n_de_location_nuts : German states (NUTS level 2) related to Partner State +* l10n_nl_location_nuts : Dutch provinces (NUTS level 3 and 4) related to Partner State diff --git a/base_location_nuts/tests/test_base_location_nuts.py b/base_location_nuts/tests/test_base_location_nuts.py index 42773cb90..b785ff517 100644 --- a/base_location_nuts/tests/test_base_location_nuts.py +++ b/base_location_nuts/tests/test_base_location_nuts.py @@ -20,14 +20,14 @@ class TestBaseLocationNuts(common.SavepointCase): cls.nuts4_1 = cls.nuts_model.search([("code", "=", "ES243")]) cls.nuts4_2 = cls.nuts_model.search([("code", "=", "ES300")]) cls.partner = cls.env["res.partner"].create( - {"name": "Test partner", "country_id": cls.country_1.id,} + {"name": "Test partner", "country_id": cls.country_1.id} ) cls.state_1 = cls.env["res.country.state"].create( - {"name": "Zaragoza Test", "code": "ZT", "country_id": cls.country_1.id,} + {"name": "Zaragoza Test", "code": "ZT", "country_id": cls.country_1.id} ) cls.nuts4_1.state_id = cls.state_1 cls.state_2 = cls.env["res.country.state"].create( - {"name": "Madrid Test", "code": "MT", "country_id": cls.country_1.id,} + {"name": "Madrid Test", "code": "MT", "country_id": cls.country_1.id} ) cls.nuts4_2.state_id = cls.state_2 cls.country_1.state_level = 4 diff --git a/base_location_nuts/views/res_partner_nuts_view.xml b/base_location_nuts/views/res_partner_nuts_view.xml index 76e5633b8..bbda3e645 100644 --- a/base_location_nuts/views/res_partner_nuts_view.xml +++ b/base_location_nuts/views/res_partner_nuts_view.xml @@ -35,7 +35,6 @@ NUTS Items res.partner.nuts - form tree,form You must click at import wizard to populate NUTS items in Odoo database in: diff --git a/base_location_nuts/wizard/nuts_import.py b/base_location_nuts/wizard/nuts_import.py index 88a234c8b..a03b85a79 100644 --- a/base_location_nuts/wizard/nuts_import.py +++ b/base_location_nuts/wizard/nuts_import.py @@ -113,7 +113,7 @@ class NutsImport(models.TransientModel): try: value = int(value) except (ValueError, TypeError): - logger.warn( + logger.warning( "Value {} for field {} replaced by 0".format(value, k) ) value = 0 @@ -170,9 +170,7 @@ class NutsImport(models.TransientModel): code = data.get("code", "") if level == 1: self._current_country = self._countries[code] - return { - "country_id": self._current_country.id, - } + return {"country_id": self._current_country.id} @api.model def create_or_update_nuts(self, node): @@ -183,7 +181,7 @@ class NutsImport(models.TransientModel): data = self._mapping(node) data.update(self.state_mapping(data, node)) level = data.get("level", 0) - if level >= 2 and level <= 5: + if 2 <= level <= 5: data["parent_id"] = self._parents[level - 2] nuts = nuts_model.search( [("level", "=", data["level"]), ("code", "=", data["code"])] @@ -192,11 +190,10 @@ class NutsImport(models.TransientModel): nuts.filtered(lambda n: not n.not_updatable).write(data) else: nuts = nuts_model.create(data) - if level >= 1 and level <= 4: + if 1 <= level <= 4: self._parents[level - 1] = nuts.id return nuts - @api.multi def run_import(self): nuts_model = self.env["res.partner.nuts"].with_context( defer_parent_store_computation=True diff --git a/base_location_nuts/wizard/nuts_import_view.xml b/base_location_nuts/wizard/nuts_import_view.xml index e237bc3ac..c66cd4ece 100644 --- a/base_location_nuts/wizard/nuts_import_view.xml +++ b/base_location_nuts/wizard/nuts_import_view.xml @@ -31,7 +31,6 @@ ir.actions.act_window nuts.import - form form new