Skip to content

Commit

Permalink
[FIX] *_location_nuts: black
Browse files Browse the repository at this point in the history
  • Loading branch information
NL66278 committed Oct 13, 2023
1 parent 07c865e commit 42b3494
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 68 deletions.
22 changes: 11 additions & 11 deletions l10n_nl_location_nuts/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'NUTS Regions for Netherlands',
'summary': 'NUTS specific options for Netherlands',
'version': '12.0.1.0.0',
'category': 'Localisation/Europe',
'website': 'https://github.com/OCA/l10n-netherlands',
'author': 'Onestein, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'depends': [
'base_location_nuts',
"name": "NUTS Regions for Netherlands",
"summary": "NUTS specific options for Netherlands",
"version": "12.0.1.0.0",
"category": "Localisation/Europe",
"website": "https://github.com/OCA/l10n-netherlands",
"author": "Onestein, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"base_location_nuts",
],
'post_init_hook': 'post_init_hook',
'installable': True,
"post_init_hook": "post_init_hook",
"installable": True,
}
6 changes: 3 additions & 3 deletions l10n_nl_location_nuts/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def post_init_hook(cr, _):
"""Define Dutch specific configuration in res.country."""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
base_nl = env.ref('base.nl')
_logger.info('Setting Netherlands NUTS configuration')
base_nl.write({'state_level': 3})
base_nl = env.ref("base.nl")
_logger.info("Setting Netherlands NUTS configuration")
base_nl.write({"state_level": 3})
43 changes: 21 additions & 22 deletions l10n_nl_location_nuts/tests/test_l10n_nl_location_nuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,48 @@


class TestNlLocationNuts(TransactionCase):

def setUp(self):
super().setUp()

if not self.env['res.country.state'].search([
('code', "=", 'NB'),
('country_id', "=", self.env.ref('base.nl').id),
]):
self.env['res.country.state'].create({
'name': 'Noord-Brabant',
'code': 'NB',
'country_id': self.env.ref('base.nl').id
})

importer = self.env['nuts.import']
if not self.env["res.country.state"].search(
[
("code", "=", "NB"),
("country_id", "=", self.env.ref("base.nl").id),
]
):
self.env["res.country.state"].create(
{
"name": "Noord-Brabant",
"code": "NB",
"country_id": self.env.ref("base.nl").id,
}
)

importer = self.env["nuts.import"]
importer.run_import()

def test_dutch_nuts(self):
"""
Test that level 3 nuts correctly bind Dutch provinces.
"""
self.nb_nuts = self.env['res.partner.nuts'].search(
[('code', '=', 'NL41')])
self.nb_nuts = self.env["res.partner.nuts"].search([("code", "=", "NL41")])
self.assertTrue(self.nb_nuts)
self.assertTrue(self.nb_nuts.state_id)

self.nl_partner = self.env['res.partner'].create({
'name': 'Dutch Partner',
'country_id': self.env.ref('base.nl').id
})
self.nl_partner = self.env["res.partner"].create(
{"name": "Dutch Partner", "country_id": self.env.ref("base.nl").id}
)
self.nl_partner.state_id = self.nb_nuts.state_id

# Onchange method binds level 3 nuts with Dutch provinces.
self.nl_partner.onchange_state_id_base_location_nuts()
self.assertEqual(
self.nl_partner.state_id,
self.nl_partner.nuts3_id.state_id)
self.assertEqual(self.nl_partner.state_id, self.nl_partner.nuts3_id.state_id)

def test_post_init_hook(self):
"""
Tests the post_init_hook.
"""
base_nl = self.env.ref('base.nl')
base_nl = self.env.ref("base.nl")
base_nl.state_level = False
self.assertFalse(base_nl.state_level)
post_init_hook(self.cr, self.env)
Expand Down
64 changes: 32 additions & 32 deletions l10n_nl_location_nuts/wizard/nuts_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@


class NutsImport(models.TransientModel):
_inherit = 'nuts.import'
_inherit = "nuts.import"
_nl_state_map = {
'NL13': 'Drenthe',
'NL23': 'Flevoland',
'NL12': 'Friesland',
'NL22': 'Gelderland',
'NL11': 'Groningen',
'NL42': 'Limburg',
'NL41': 'Noord-Brabant',
'NL32': 'Noord-Holland',
'NL21': 'Overijssel',
'NL31': 'Utrecht',
'NL34': 'Zeeland',
'NL33': 'Zuid-Holland',
"NL13": "Drenthe",
"NL23": "Flevoland",
"NL12": "Friesland",
"NL22": "Gelderland",
"NL11": "Groningen",
"NL42": "Limburg",
"NL41": "Noord-Brabant",
"NL32": "Noord-Holland",
"NL21": "Overijssel",
"NL31": "Utrecht",
"NL34": "Zeeland",
"NL33": "Zuid-Holland",
}

_nl_state_ids = {
'Drenthe': 0,
'Flevoland': 0,
'Friesland': 0,
'Gelderland': 0,
'Groningen': 0,
'Limburg': 0,
'Noord-Brabant': 0,
'Noord-Holland': 0,
'Overijssel': 0,
'Utrecht': 0,
'Zeeland': 0,
'Zuid-Holland': 0,
"Drenthe": 0,
"Flevoland": 0,
"Friesland": 0,
"Gelderland": 0,
"Groningen": 0,
"Limburg": 0,
"Noord-Brabant": 0,
"Noord-Holland": 0,
"Overijssel": 0,
"Utrecht": 0,
"Zeeland": 0,
"Zuid-Holland": 0,
}

@api.model
def state_mapping(self, data, node):
mapping = super().state_mapping(data, node)

# fill map _nl_state_ids with currently used ids
nl_provinces = self.env['res.country.state'].search([
('country_id', '=', self.env.ref('base.nl').id)
])
nl_provinces = self.env["res.country.state"].search(
[("country_id", "=", self.env.ref("base.nl").id)]
)
for province in nl_provinces:
if province.name in self._nl_state_ids:
self._nl_state_ids[province.name] = province.id

# complete the mapping of the state_id with the Dutch provinces
level = data.get('level', 0)
code = data.get('code', '')
if self._current_country.code == 'NL' and level in [3, 4]:
level = data.get("level", 0)
code = data.get("code", "")
if self._current_country.code == "NL" and level in [3, 4]:
code_ref = code if level == 3 else code[:-1]
external_ref = self._nl_state_map.get(code_ref)
if external_ref and self._nl_state_ids[external_ref]:
mapping['state_id'] = self._nl_state_ids[external_ref]
mapping["state_id"] = self._nl_state_ids[external_ref]

return mapping

0 comments on commit 42b3494

Please sign in to comment.