Browse Source

[MIG] base_location_nuts: Migration to 11.0

pull/739/head
agaldona 7 years ago
committed by Alexandre Díaz
parent
commit
4c20b6e282
  1. 3
      base_location_nuts/README.rst
  2. 2
      base_location_nuts/__init__.py
  3. 7
      base_location_nuts/__manifest__.py
  4. 2
      base_location_nuts/models/__init__.py
  5. 1
      base_location_nuts/models/res_country.py
  6. 1
      base_location_nuts/models/res_partner.py
  7. 2
      base_location_nuts/models/res_partner_nuts.py
  8. 2
      base_location_nuts/tests/__init__.py
  9. 1
      base_location_nuts/tests/test_base_location_nuts.py
  10. 2
      base_location_nuts/views/res_partner_nuts_view.xml
  11. 2
      base_location_nuts/wizard/__init__.py
  12. 18
      base_location_nuts/wizard/nuts_import.py
  13. 4
      base_location_nuts/wizard/nuts_import_view.xml

3
base_location_nuts/README.rst

@ -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
============
@ -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
===========

2
base_location_nuts/__init__.py

@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard

7
base_location_nuts/__manifest__.py

@ -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>
@ -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',
@ -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
base_location_nuts/models/__init__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from . import res_country
from . import res_partner
from . import res_partner_nuts

1
base_location_nuts/models/res_country.py

@ -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).

1
base_location_nuts/models/res_partner.py

@ -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).

2
base_location_nuts/models/res_partner_nuts.py

@ -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).

2
base_location_nuts/tests/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import test_base_location_nuts

1
base_location_nuts/tests/test_base_location_nuts.py

@ -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).

2
base_location_nuts/views/res_partner_nuts_view.xml

@ -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
base_location_nuts/wizard/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import nuts_import

18
base_location_nuts/wizard/nuts_import.py

@ -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>
@ -79,7 +78,7 @@ class NutsImport(models.TransientModel):
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')
@ -118,11 +117,11 @@ class NutsImport(models.TransientModel):
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))
@ -133,15 +132,15 @@ class NutsImport(models.TransientModel):
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:
@ -190,7 +189,8 @@ class NutsImport(models.TransientModel):
# 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()

4
base_location_nuts/wizard/nuts_import_view.xml

@ -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>
Loading…
Cancel
Save