diff --git a/base_location_nuts/README.rst b/base_location_nuts/README.rst index 26215f870..0978044f8 100644 --- a/base_location_nuts/README.rst +++ b/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 -`_. 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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Tecnativa +* Agile Business Group + Contributors ------------- +~~~~~~~~~~~~ * Rafael Blasco * Antonio Espinosa * Jairo Llopis * David Vidal +* Simone Rubino -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_location_nuts/__manifest__.py b/base_location_nuts/__manifest__.py index dfe8ccedb..a5a5b8f33 100644 --- a/base_location_nuts/__manifest__.py +++ b/base_location_nuts/__manifest__.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Copyright 2015 Antonio Espinosa # Copyright 2016 Jairo Llopis # Copyright 2017 David Vidal @@ -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', diff --git a/base_location_nuts/models/res_partner_nuts.py b/base_location_nuts/models/res_partner_nuts.py index 25e232937..c2a8ef446 100644 --- a/base_location_nuts/models/res_partner_nuts.py +++ b/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') diff --git a/base_location_nuts/readme/CONFIGURE.rst b/base_location_nuts/readme/CONFIGURE.rst new file mode 100644 index 000000000..f8b59fd9c --- /dev/null +++ b/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. diff --git a/base_location_nuts/readme/CONTRIBUTORS.rst b/base_location_nuts/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..afbaec99e --- /dev/null +++ b/base_location_nuts/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Rafael Blasco +* Antonio Espinosa +* Jairo Llopis +* David Vidal +* Simone Rubino diff --git a/base_location_nuts/readme/DESCRIPTION.rst b/base_location_nuts/readme/DESCRIPTION.rst new file mode 100644 index 000000000..61c47e9cd --- /dev/null +++ b/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. diff --git a/base_location_nuts/readme/INSTALL.rst b/base_location_nuts/readme/INSTALL.rst new file mode 100644 index 000000000..d0d761c31 --- /dev/null +++ b/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 diff --git a/base_location_nuts/readme/USAGE.rst b/base_location_nuts/readme/USAGE.rst new file mode 100644 index 000000000..8f509c757 --- /dev/null +++ b/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. diff --git a/base_location_nuts/tests/test_base_location_nuts.py b/base_location_nuts/tests/test_base_location_nuts.py index 6c1d68e0b..0b69700b9 100644 --- a/base_location_nuts/tests/test_base_location_nuts.py +++ b/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()) diff --git a/base_location_nuts/views/res_partner_nuts_view.xml b/base_location_nuts/views/res_partner_nuts_view.xml index 3e1c56423..34e3ec609 100644 --- a/base_location_nuts/views/res_partner_nuts_view.xml +++ b/base_location_nuts/views/res_partner_nuts_view.xml @@ -14,7 +14,7 @@ - NUTS Items tree + NUTS Items form res.partner.nuts
@@ -24,6 +24,7 @@ + diff --git a/base_location_nuts/wizard/nuts_import.py b/base_location_nuts/wizard/nuts_import.py index c756b6257..322463b74 100644 --- a/base_location_nuts/wizard/nuts_import.py +++ b/base_location_nuts/wizard/nuts_import.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Copyright 2015 Antonio Espinosa # Copyright 2016 Jairo Llopis # Copyright 2017 David Vidal @@ -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() diff --git a/base_location_nuts/wizard/nuts_import_view.xml b/base_location_nuts/wizard/nuts_import_view.xml index 803fc1aec..8ccf70dda 100644 --- a/base_location_nuts/wizard/nuts_import_view.xml +++ b/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'.