Skip to content

Commit

Permalink
[MIG] base_location_nuts: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincenzo9191 authored and FrancescoCosma committed Mar 10, 2023
1 parent c4721ee commit 281f159
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion base_location_nuts/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "NUTS Regions",
"category": "Localisation/Europe",
"version": "14.0.1.0.1",
"version": "16.0.1.0.0",
"depends": ["contacts"],
"data": [
"views/res_country_view.xml",
Expand Down
2 changes: 1 addition & 1 deletion base_location_nuts/models/res_partner_nuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ResPartnerNuts(models.Model):
not_updatable = fields.Boolean()
# Parent hierarchy
parent_id = fields.Many2one(comodel_name="res.partner.nuts", ondelete="restrict")
parent_path = fields.Char(index=True)
parent_path = fields.Char(index=True, unaccent=False)
child_ids = fields.One2many(
comodel_name="res.partner.nuts", inverse_name="parent_id", string="Children"
)
2 changes: 1 addition & 1 deletion base_location_nuts/tests/test_base_location_nuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from odoo.tests import common


class TestBaseLocationNuts(common.SavepointCase):
class TestBaseLocationNuts(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestBaseLocationNuts, cls).setUpClass()
Expand Down
2 changes: 1 addition & 1 deletion base_location_nuts/views/res_partner_nuts_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<field name="name">NUTS Items tree</field>
<field name="model">res.partner.nuts</field>
<field name="arch" type="xml">
<tree string="NUTS Items">
<tree>
<field name="level" />
<field name="code" />
<field name="name" />
Expand Down
22 changes: 13 additions & 9 deletions base_location_nuts/wizard/nuts_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
from collections import OrderedDict

import requests
import urllib3
from lxml import etree

from odoo import _, api, fields, models
Expand Down Expand Up @@ -121,7 +121,7 @@ def _mapping(self, node):
else:
logger.debug("xpath = '%s', not found" % field_xpath)
if field_required and not value:
raise UserError(_("Value not found for mandatory field %s" % k))
raise UserError(_("Value not found for mandatory field %s") % k)
item[k] = value
return item

Expand All @@ -136,20 +136,24 @@ def _download_nuts(self, url_base=None, url_path=None, url_params=None):
url += "&".join([k + "=" + v for k, v in url_params.items()])
logger.info("Starting to download %s" % url)
try:
res_request = requests.get(url)
http = urllib3.PoolManager()
res_request = http.request("GET", url)
except Exception as e:
raise UserError(
_("Got an error when trying to download the file: %s.") % str(e)
)
if res_request.status_code != requests.codes.ok:
) from e
if res_request.status != 200:
raise UserError(
_("Got an error %d when trying to download the file %s.")
% (res_request.status_code, url)
_(
"Got an error %(d)s when trying to download the file %(s)s.",
d=res_request.status,
s=url,
)
)
logger.info("Download successfully %d bytes" % len(res_request.content))
logger.info("Download successfully %d bytes" % len(res_request.data))
# Workaround XML: Remove all characters before <?xml
pattern = re.compile(rb"^.*<\?xml", re.DOTALL)
content_fixed = re.sub(pattern, b"<?xml", res_request.content)
content_fixed = re.sub(pattern, b"<?xml", res_request.data)
if not re.match(rb"<\?xml", content_fixed):
raise UserError(_("Downloaded file is not a valid XML file"))
return content_fixed
Expand Down
1 change: 1 addition & 0 deletions setup/base_location_nuts/odoo/addons/base_location_nuts
6 changes: 6 additions & 0 deletions setup/base_location_nuts/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 281f159

Please sign in to comment.