Browse Source

[13.0][MIG] base_location_nuts

14.0
Andrea 5 years ago
committed by Andrii Skrypka
parent
commit
a7817d108c
  1. 4
      base_location_nuts/README.rst
  2. 6
      base_location_nuts/__manifest__.py
  3. 6
      base_location_nuts/migrations/12.0.1.0.0/post-migration.py
  4. 20
      base_location_nuts/models/res_partner.py
  5. 11
      base_location_nuts/models/res_partner_nuts.py
  6. 2
      base_location_nuts/readme/CONFIGURE.rst
  7. 1
      base_location_nuts/readme/CONTRIBUTORS.rst
  8. 1
      base_location_nuts/readme/INSTALL.rst
  9. 6
      base_location_nuts/tests/test_base_location_nuts.py
  10. 1
      base_location_nuts/views/res_partner_nuts_view.xml
  11. 11
      base_location_nuts/wizard/nuts_import.py
  12. 1
      base_location_nuts/wizard/nuts_import_view.xml

4
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,

6
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",

6
base_location_nuts/migrations/12.0.1.0.0/post-migration.py

@ -1,6 +0,0 @@
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
env["res.partner.nuts"]._parent_store_compute()

20
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):

11
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"
)

2
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,

1
base_location_nuts/readme/CONTRIBUTORS.rst

@ -4,3 +4,4 @@
* David Vidal <david.vidal@tecnativa.com>
* Simone Rubino <simone.rubino@agilebg.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
* Andrea Stirpe <a.stirpe@onestein.nl>

1
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

6
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

1
base_location_nuts/views/res_partner_nuts_view.xml

@ -35,7 +35,6 @@
<record id="res_partner_nuts_action" model="ir.actions.act_window">
<field name="name">NUTS Items</field>
<field name="res_model">res.partner.nuts</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help">You must click at import wizard to populate NUTS items
in Odoo database in:

11
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

1
base_location_nuts/wizard/nuts_import_view.xml

@ -31,7 +31,6 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">nuts.import</field>
<field name="view_id" ref="nuts_import_form" />
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

Loading…
Cancel
Save