Skip to content

Commit

Permalink
[MIG] base_location_nuts: Migration to 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agaldona authored and yajo committed Dec 5, 2017
1 parent 03f7470 commit e014100
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 31 deletions.
3 changes: 2 additions & 1 deletion base_location_nuts/README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

============
Expand Down Expand Up @@ -48,7 +49,7 @@ in order to allow to assign them to partner object.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/10.0
:target: https://runbot.odoo-community.org/runbot/134/11.0

Bug Tracker
===========
Expand Down
2 changes: 0 additions & 2 deletions base_location_nuts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-

from . import models
from . import wizard
7 changes: 3 additions & 4 deletions base_location_nuts/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
Expand All @@ -7,9 +6,9 @@
{
'name': 'NUTS Regions',
'category': 'Localisation/Europe',
'version': '10.0.1.0.0',
'version': '11.0.1.0.0',
'depends': [
'sales_team',
'contacts',
],
'data': [
'views/res_country_view.xml',
Expand All @@ -23,7 +22,7 @@
],
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'https://www.tecnativa.com',
'website': 'https://github.com/OCA/partner-contact/',
'license': 'AGPL-3',
'installable': True,
}
2 changes: 0 additions & 2 deletions base_location_nuts/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from . import res_country
from . import res_partner
from . import res_partner_nuts
1 change: 0 additions & 1 deletion base_location_nuts/models/res_country.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
Expand Down
1 change: 0 additions & 1 deletion base_location_nuts/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand Down
2 changes: 0 additions & 2 deletions base_location_nuts/models/res_partner_nuts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
Expand Down
2 changes: 0 additions & 2 deletions base_location_nuts/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import test_base_location_nuts
1 change: 0 additions & 1 deletion base_location_nuts/tests/test_base_location_nuts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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 @@ -68,7 +68,7 @@
<menuitem action="res_partner_nuts_action"
id="res_partner_nuts_menu"
name="NUTS Items"
parent="sales_team.menu_localisation"
parent="contacts.menu_localisation"
sequence="40"/>

</odoo>
2 changes: 0 additions & 2 deletions base_location_nuts/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import nuts_import
18 changes: 9 additions & 9 deletions base_location_nuts/wizard/nuts_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2017 David Vidal <jairo.llopis@tecnativa.com>
Expand Down Expand Up @@ -79,7 +78,7 @@ def _check_node(self, node):

def _mapping(self, node):
item = {}
for k, v in self._map.iteritems():
for k, v in self._map.items():
field_xpath = v.get('xpath', '')
field_attrib = v.get('attrib', False)
field_type = v.get('type', 'string')
Expand Down Expand Up @@ -118,11 +117,11 @@ def _download_nuts(self, url_base=None, url_path=None, url_params=None):
if not url_params:
url_params = URL_PARAMS
url = url_base + url_path + '?'
url += '&'.join([k + '=' + v for k, v in url_params.iteritems()])
url += '&'.join([k + '=' + v for k, v in url_params.items()])
logger.info('Starting to download %s' % url)
try:
res_request = requests.get(url)
except Exception, e:
except Exception as e:
raise UserError(
_('Got an error when trying to download the file: %s.') %
str(e))
Expand All @@ -133,15 +132,15 @@ def _download_nuts(self, url_base=None, url_path=None, url_params=None):
logger.info('Download successfully %d bytes' %
len(res_request.content))
# Workaround XML: Remove all characters before <?xml
pattern = re.compile(r'^.*<\?xml', re.DOTALL)
content_fixed = re.sub(pattern, '<?xml', res_request.content)
if not re.match(r'<\?xml', content_fixed):
pattern = re.compile(rb'^.*<\?xml', re.DOTALL)
content_fixed = re.sub(pattern, b'<?xml', res_request.content)
if not re.match(rb'<\?xml', content_fixed):
raise UserError(_('Downloaded file is not a valid XML file'))
return content_fixed

@api.model
def _load_countries(self):
for k in self._countries.keys():
for k in self._countries:
self._countries[k] = self.env['res.country'].search(
[('code', '=', k)])
# Workaround to translate some country codes:
Expand Down Expand Up @@ -190,7 +189,8 @@ def run_import(self):
# All current NUTS (for available countries),
# delete if not found above
nuts_to_delete = nuts_model.search(
[('country_id', 'in', [x.id for x in self._countries.values()])])
[('country_id', 'in',
[x.id for x in self._countries.values()])])
# Download NUTS in english, create or update
logger.info('Importing NUTS 2013 English...')
xmlcontent = self._download_nuts()
Expand Down
4 changes: 1 addition & 3 deletions base_location_nuts/wizard/nuts_import_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
<menuitem action="nuts_import_action"
id="nuts_import_menu"
name="Import NUTS 2013"
parent="sales_team.menu_localisation"
parent="contacts.menu_localisation"
sequence="45"/>

<record id="config_wizard_nuts" model="ir.actions.todo">
<field name="name">Import NUTS 2013 from RAMON</field>
<field name="note">You can import NUTS from RAMON european service.</field>
<field name="action_id" ref="nuts_import_action"/>
<field name="sequence">20</field>
<field name="type">automatic</field>
</record>

</odoo>

0 comments on commit e014100

Please sign in to comment.