Browse Source

[UPD] base_location_nuts: update based on flag

pull/739/head
SimoRubi 6 years ago
committed by Alexandre Díaz
parent
commit
58ba5aafc2
  1. 73
      base_location_nuts/README.rst
  2. 4
      base_location_nuts/__manifest__.py
  3. 1
      base_location_nuts/models/res_partner_nuts.py
  4. 9
      base_location_nuts/readme/CONFIGURE.rst
  5. 5
      base_location_nuts/readme/CONTRIBUTORS.rst
  6. 13
      base_location_nuts/readme/DESCRIPTION.rst
  7. 5
      base_location_nuts/readme/INSTALL.rst
  8. 3
      base_location_nuts/readme/USAGE.rst
  9. 61
      base_location_nuts/tests/test_base_location_nuts.py
  10. 3
      base_location_nuts/views/res_partner_nuts_view.xml
  11. 7
      base_location_nuts/wizard/nuts_import.py
  12. 2
      base_location_nuts/wizard/nuts_import_view.xml

73
base_location_nuts/README.rst

@ -1,11 +1,30 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
============
NUTS Regions
============
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/11.0/base_location_nuts
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-11-0/partner-contact-11-0-base_location_nuts
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/134/11.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module allows to import NUTS locations.
Creates four new fields in Partner object, one per NUTS level
@ -15,6 +34,15 @@ Creates four new fields in Partner object, one per NUTS level
* NUTS L3: Normally substate or state level
* NUTS L4: Normally small region or province level
This module allows to set the flag *Not updatable* in a NUTS region so that it gets no more updated nor deleted by the import wizard.
Usually NUTS regions have to stay updated with the real ones, but the user may want to update a region's field (name, parent, ...) or create a new ones.
With this module, flagging such records as *Not updatable* prevents them from being overwritten or deleted by the import wizard.
**Table of contents**
.. contents::
:local:
Installation
============
@ -25,7 +53,6 @@ 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
Configuration
=============
@ -39,7 +66,6 @@ l10n_de_location_nuts, ...) will inherit this wizard and
relate each NUTS item with states. So if you install a new localization addon
you must re-build NUTS clicking this wizard again.
Usage
=====
@ -47,40 +73,47 @@ Only Administrator can manage NUTS list (it is not neccesary because
it is an European convention) but any registered user can read them,
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/11.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner_contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20base_location_nuts%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Tecnativa
* Agile Business Group
Contributors
------------
~~~~~~~~~~~~
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Simone Rubino <simone.rubino@agilebg.com>
Maintainers
~~~~~~~~~~~
Maintainer
----------
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/11.0/base_location_nuts>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

4
base_location_nuts/__manifest__.py

@ -1,3 +1,4 @@
# -*- 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>
@ -6,7 +7,7 @@
{
'name': 'NUTS Regions',
'category': 'Localisation/Europe',
'version': '11.0.1.0.0',
'version': '11.0.1.1.0',
'depends': [
'contacts',
],
@ -21,6 +22,7 @@
'images/new_fields.png',
],
'author': 'Tecnativa, '
'Agile Business Group, '
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/partner-contact/',
'license': 'AGPL-3',

1
base_location_nuts/models/res_partner_nuts.py

@ -20,6 +20,7 @@ class ResPartnerNuts(models.Model):
required=True)
state_id = fields.Many2one(comodel_name='res.country.state',
string='State')
not_updatable = fields.Boolean()
# Parent hierarchy
parent_id = fields.Many2one(comodel_name='res.partner.nuts',
ondelete='restrict')

9
base_location_nuts/readme/CONFIGURE.rst

@ -0,0 +1,9 @@
After installation, you must click at import wizard to populate NUTS items
in Odoo database in:
Sales > Configuration > Address Book > 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,
l10n_de_location_nuts, ...) will inherit this wizard and
relate each NUTS item with states. So if you install a new localization addon
you must re-build NUTS clicking this wizard again.

5
base_location_nuts/readme/CONTRIBUTORS.rst

@ -0,0 +1,5 @@
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Simone Rubino <simone.rubino@agilebg.com>

13
base_location_nuts/readme/DESCRIPTION.rst

@ -0,0 +1,13 @@
This module allows to import NUTS locations.
Creates four new fields in Partner object, one per NUTS level
* NUTS L1: Country level
* NUTS L2: Normally state or big region level
* NUTS L3: Normally substate or state level
* NUTS L4: Normally small region or province level
This module allows to set the flag *Not updatable* in a NUTS region so that it gets no more updated nor deleted by the import wizard.
Usually NUTS regions have to stay updated with the real ones, but the user may want to update a region's field (name, parent, ...) or create a new ones.
With this module, flagging such records as *Not updatable* prevents them from being overwritten or deleted by the import wizard.

5
base_location_nuts/readme/INSTALL.rst

@ -0,0 +1,5 @@
We recommend to install another addon (one for each country) in order to relate
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

3
base_location_nuts/readme/USAGE.rst

@ -0,0 +1,3 @@
Only Administrator can manage NUTS list (it is not neccesary because
it is an European convention) but any registered user can read them,
in order to allow to assign them to partner object.

61
base_location_nuts/tests/test_base_location_nuts.py

@ -13,16 +13,12 @@ class TestBaseLocationNuts(common.SavepointCase):
cls.importer.run_import() # loads nuts
cls.country_1 = cls.env['res.country'].search([('code', '=', 'ES')])
cls.country_2 = cls.env['res.country'].search([('code', '=', 'PT')])
cls.nuts1_2 = cls.env[
'res.partner.nuts'].search([('code', '=', 'PT')])
cls.nuts2_1 = cls.env[
'res.partner.nuts'].search([('code', '=', 'ES2')])
cls.nuts3_1 = cls.env[
'res.partner.nuts'].search([('code', '=', 'ES24')])
cls.nuts4_1 = cls.env[
'res.partner.nuts'].search([('code', '=', 'ES243')])
cls.nuts4_2 = cls.env[
'res.partner.nuts'].search([('code', '=', 'ES300')])
cls.nuts_model = cls.env['res.partner.nuts']
cls.nuts1_2 = cls.nuts_model.search([('code', '=', 'PT')])
cls.nuts2_1 = cls.nuts_model.search([('code', '=', 'ES2')])
cls.nuts3_1 = cls.nuts_model.search([('code', '=', 'ES24')])
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,
@ -87,3 +83,48 @@ class TestBaseLocationNuts(common.SavepointCase):
self.importer._download_nuts(url_base='htttt://test.com')
with self.assertRaises(UserError):
self.importer._download_nuts(url_base='http://ec.europa.eu/_404')
def create_new_parent(self, orig_parent):
new_parent = self.nuts_model.create({
'level': orig_parent.level,
'code': 'NEW' + orig_parent.code,
'name': 'New parent',
'country_id': orig_parent.country_id.id,
'not_updatable': False
})
return new_parent
def test_no_update(self):
# Update a NUTS field
orig_name = self.nuts4_2.name
new_name = 2 * orig_name
self.assertNotEqual(orig_name, new_name)
# Update hierarchy creating a new parent
orig_parent = self.nuts4_2.parent_id
new_parent = self.create_new_parent(orig_parent)
self.assertNotEqual(orig_parent, new_parent)
# If the flag is False (default), updates will be overwritten
# and the new parent deleted
self.assertFalse(self.nuts4_2.not_updatable)
self.assertFalse(new_parent.not_updatable)
self.nuts4_2.name = new_name
self.nuts4_2.parent_id = new_parent
self.importer.run_import()
self.assertEqual(self.nuts4_2.name, orig_name)
self.assertEqual(self.nuts4_2.parent_id, orig_parent)
self.assertFalse(new_parent.exists())
# New parent has been deleted by the import
new_parent = self.create_new_parent(orig_parent)
# If the flag is True, creation and updates will not be overwritten
self.nuts4_2.not_updatable = True
new_parent.not_updatable = True
self.nuts4_2.name = new_name
self.nuts4_2.parent_id = new_parent
self.importer.run_import()
self.assertEqual(self.nuts4_2.name, new_name)
self.assertEqual(self.nuts4_2.parent_id, new_parent)
self.assertTrue(new_parent.exists())

3
base_location_nuts/views/res_partner_nuts_view.xml

@ -14,7 +14,7 @@
</record>
<record id="res_partner_nuts_form" model="ir.ui.view">
<field name="name">NUTS Items tree</field>
<field name="name">NUTS Items form</field>
<field name="model">res.partner.nuts</field>
<field name="arch" type="xml">
<form string="NUTS Item">
@ -24,6 +24,7 @@
<field name="code"/>
<field name="parent_id"/>
<field name="name"/>
<field name="not_updatable"/>
</group>
<group>
<field name="country_id"/>

7
base_location_nuts/wizard/nuts_import.py

@ -1,3 +1,4 @@
# -*- 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>
@ -174,7 +175,7 @@ class NutsImport(models.TransientModel):
nuts = nuts_model.search([('level', '=', data['level']),
('code', '=', data['code'])])
if nuts:
nuts.write(data)
nuts.filtered(lambda n: not n.not_updatable).write(data)
else:
nuts = nuts_model.create(data)
if level >= 1 and level <= 4:
@ -189,8 +190,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()]),
('not_updatable', '=', False)])
# Download NUTS in english, create or update
logger.info('Importing NUTS 2013 English...')
xmlcontent = self._download_nuts()

2
base_location_nuts/wizard/nuts_import_view.xml

@ -12,6 +12,8 @@
Updating or creating new NUTS entries if not
found already in the system, and DELETING MISSING
ENTRIES from new downloaded file.
Update or deletion is prevented for NUTS entries with the flag 'Not updatable'.
</div>
<footer>
<button name="run_import" type="object"

Loading…
Cancel
Save