Skip to content

Commit

Permalink
[MIG] l10n_it_location_nuts: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
renda-dev committed Nov 25, 2024
1 parent a076aed commit 573f86d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion l10n_it_location_nuts/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "ITA - Regioni NUTS",
"summary": "Opzioni NUTS specifiche per l'Italia",
"version": "14.0.1.1.0",
"version": "16.0.1.0.0",
"category": "Localization/Europe",
"website": "https://github.com/OCA/l10n-italy",
"author": "Agile Business Group, " "Odoo Community Association (OCA)",
Expand Down
9 changes: 4 additions & 5 deletions l10n_it_location_nuts/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

def post_init_hook(cr, registry):
"""Define Italian specific configuration in res.country."""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
italy = env.ref("base.it")
_logger.info("Setting Italy NUTS configuration")
italy.write({"state_level": 4})
env = api.Environment(cr, SUPERUSER_ID, {})
italy = env.ref("base.it")
_logger.info("Setting Italy NUTS configuration")
italy.write({"state_level": 4})
2 changes: 1 addition & 1 deletion l10n_it_location_nuts/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

# from . import test_nuts
from . import test_nuts
8 changes: 4 additions & 4 deletions l10n_it_location_nuts/tests/test_nuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestNUTS(SavepointCase):
class TestNUTS(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestNUTS, cls).setUpClass()
super().setUpClass()
importer = cls.env["nuts.import"].create([{}])
importer.run_import()
importer.import_update_partner_nuts()
cls.rome_nuts = cls.env["res.partner.nuts"].search([("code", "=", "ITI43")])
rome_state_id = cls.env.ref("base.state_it_rm").id
cls.it_partner = cls.env["res.partner"].create({"name": "it_partner"})
Expand Down
20 changes: 7 additions & 13 deletions l10n_it_location_nuts/wizard/nuts_import.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2018 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models
from odoo import models


class NutsImport(models.TransientModel):
Expand Down Expand Up @@ -119,15 +119,9 @@ class NutsImport(models.TransientModel):
"ITI41": "base.state_it_vt", # Viterbo
}

@api.model
def state_mapping(self, data, node):
mapping = super(NutsImport, self).state_mapping(data, node)
level = data.get("level", 0)
code = data.get("code", "")
if self.current_country_id.code == "IT" and level == 4:
external_ref = self._it_state_map.get(code, False)
if external_ref:
state = self.env.ref(external_ref)
if state:
mapping["state_id"] = state.id
return mapping
def _create_partner_nuts(self, nuts_data):
nuts_ids = super()._create_partner_nuts(nuts_data)
for nut in nuts_ids:
if self._it_state_map.get(nut.code, False):
nut.state_id = self.env.ref(self._it_state_map[nut.code])
return nuts_ids

0 comments on commit 573f86d

Please sign in to comment.