diff --git a/base_location_nuts/README.rst b/base_location_nuts/README.rst index 18c380523..39c4c3545 100644 --- a/base_location_nuts/README.rst +++ b/base_location_nuts/README.rst @@ -7,28 +7,22 @@ NUTS Regions This module allows to import NUTS locations. -Creates two new fields in Partner object: +Creates four new fields in Partner object, one per NUTS level -* Region (res.partner.region): Classification over state, automatically - calculated when state is selected -* Substate (res.partner.substate): Classification above state, user must select - one from available for selected state +* 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 Installation ============ -You need to install another addon (one for each country) in order to use -these NUTS, for example: +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) as Partner State - * Spanish Autonomous communities (NUTS level 3) as Partner Substate - * Spanish Regions (NUTS level 2) as Partner Region -* l10n_de_location_nuts : - * German states (NUTS level 2) as Partner State - * German districts (NUTS level 3) as Partner Substate - * German regions (NUTS level 4) as Partner Region +* 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 @@ -54,8 +48,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/{branch} - + :target: https://runbot.odoo-community.org/runbot/134/8.0 Bug Tracker =========== @@ -74,6 +67,7 @@ Contributors * Rafael Blasco * Antonio Espinosa +* Jairo Llopis Maintainer ---------- @@ -88,4 +82,4 @@ 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 http://odoo-community.org. \ No newline at end of file +To contribute to this module, please visit http://odoo-community.org. diff --git a/base_location_nuts/__openerp__.py b/base_location_nuts/__openerp__.py index a1aad7791..e1f7cb650 100644 --- a/base_location_nuts/__openerp__.py +++ b/base_location_nuts/__openerp__.py @@ -24,16 +24,20 @@ { 'name': 'NUTS Regions', 'category': 'Localisation/Europe', - 'version': '8.0.1.0.0', + 'version': '8.0.2.0.0', 'depends': [ 'base', ], 'data': [ + 'views/res_country_view.xml', 'views/res_partner_nuts_view.xml', 'views/res_partner_view.xml', 'wizard/nuts_import_view.xml', 'security/ir.model.access.csv', ], + 'images': [ + 'images/new_fields.png', + ], 'author': 'Antiun Ingeniería S.L., ' 'Odoo Community Association (OCA)', 'website': 'http://www.antiun.com', diff --git a/base_location_nuts/i18n/base_location_nuts.pot b/base_location_nuts/i18n/base_location_nuts.pot deleted file mode 100644 index 82a4f0117..000000000 --- a/base_location_nuts/i18n/base_location_nuts.pot +++ /dev/null @@ -1,214 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * base_location_nuts -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-06-11 15:26+0000\n" -"PO-Revision-Date: 2015-06-11 15:26+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: base_location_nuts -#: view:nuts.import:base_location_nuts.nuts_import_form -msgid "Cancel" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,children:0 -msgid "Children" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,code:0 -msgid "Code" -msgstr "" - -#. module: base_location_nuts -#: view:res.partner.nuts:base_location_nuts.view_res_partner_nuts_filter -#: field:res.partner.nuts,country_id:0 -msgid "Country" -msgstr "" - -#. module: base_location_nuts -#: field:nuts.import,create_uid:0 -#: field:res.partner.nuts,create_uid:0 -msgid "Created by" -msgstr "" - -#. module: base_location_nuts -#: field:nuts.import,create_date:0 -#: field:res.partner.nuts,create_date:0 -msgid "Created on" -msgstr "" - -#. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:149 -#, python-format -msgid "Downloaded file is not a valid XML file" -msgstr "" - -#. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:141 -#, python-format -msgid "Got an error %d when trying to download the file %s." -msgstr "" - -#. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:137 -#, python-format -msgid "Got an error when trying to download the file: %s." -msgstr "" - -#. module: base_location_nuts -#: view:res.partner.nuts:base_location_nuts.view_res_partner_nuts_filter -msgid "Group By" -msgstr "" - -#. module: base_location_nuts -#: field:nuts.import,id:0 -#: field:res.partner.nuts,id:0 -msgid "ID" -msgstr "" - -#. module: base_location_nuts -#: view:nuts.import:base_location_nuts.nuts_import_form -msgid "Import" -msgstr "" - -#. module: base_location_nuts -#: model:ir.ui.menu,name:base_location_nuts.nuts_import_menu -msgid "Import NUTS 2013" -msgstr "" - -#. module: base_location_nuts -#: model:ir.actions.act_window,name:base_location_nuts.nuts_import_action -#: view:nuts.import:base_location_nuts.nuts_import_form -msgid "Import NUTS 2013 from RAMON" -msgstr "" - -#. module: base_location_nuts -#: model:ir.model,name:base_location_nuts.model_nuts_import -msgid "Import NUTS items from European RAMON service" -msgstr "" - -#. module: base_location_nuts -#: field:nuts.import,write_uid:0 -#: field:res.partner.nuts,write_uid:0 -msgid "Last Updated by" -msgstr "" - -#. module: base_location_nuts -#: field:nuts.import,write_date:0 -#: field:res.partner.nuts,write_date:0 -msgid "Last Updated on" -msgstr "" - -#. module: base_location_nuts -#: view:res.partner.nuts:base_location_nuts.view_res_partner_nuts_filter -#: field:res.partner.nuts,level:0 -msgid "Level" -msgstr "" - -#. module: base_location_nuts -#: model:ir.model,name:base_location_nuts.model_res_partner_nuts -#: view:res.partner.nuts:base_location_nuts.res_partner_nuts_form -msgid "NUTS Item" -msgstr "" - -#. module: base_location_nuts -#: model:ir.actions.act_window,name:base_location_nuts.res_partner_nuts_action -#: model:ir.ui.menu,name:base_location_nuts.res_partner_nuts_menu -#: view:res.partner.nuts:base_location_nuts.res_partner_nuts_tree -msgid "NUTS Items" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,name:0 -msgid "Name" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,parent_left:0 -msgid "Parent Left" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,parent_right:0 -msgid "Parent Right" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,parent_id:0 -msgid "Parent id" -msgstr "" - -#. module: base_location_nuts -#: model:ir.model,name:base_location_nuts.model_res_partner -msgid "Partner" -msgstr "" - -#. module: base_location_nuts -#: code:addons/base_location_nuts/models/res_partner.py:53 -#: view:res.partner:base_location_nuts.view_res_partner_filter_nuts -#: field:res.partner,region:0 -#, python-format -msgid "Region" -msgstr "" - -#. module: base_location_nuts -#: view:res.partner:base_location_nuts.view_res_partner_filter_nuts -msgid "Salesperson" -msgstr "" - -#. module: base_location_nuts -#: view:res.partner.nuts:base_location_nuts.view_res_partner_nuts_filter -msgid "Search NUTS" -msgstr "" - -#. module: base_location_nuts -#: field:res.partner.nuts,state_id:0 -msgid "State" -msgstr "" - -#. module: base_location_nuts -#: code:addons/base_location_nuts/models/res_partner.py:54 -#: view:res.partner:base_location_nuts.view_res_partner_filter_nuts -#: field:res.partner,substate:0 -#, python-format -msgid "Substate" -msgstr "" - -#. module: base_location_nuts -#: view:nuts.import:base_location_nuts.nuts_import_form -msgid "This wizard will download the lastest version of\n" -" NUTS 2013 from Europe RAMON metadata service.\n" -" Updating or creating new NUTS entries if not\n" -" found already in the system, and DELETING MISSING\n" -" ENTRIES from new downloaded file." -msgstr "" - -#. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:116 -#, python-format -msgid "Value not found for mandatory field %s" -msgstr "" - -#. module: base_location_nuts -#: model:ir.actions.todo,note:base_location_nuts.config_wizard_nuts -msgid "You can import NUTS from RAMON european service." -msgstr "" - -#. module: base_location_nuts -#: model:ir.actions.act_window,help:base_location_nuts.res_partner_nuts_action -msgid "You must click at import wizard to populate NUTS items\n" -" in Odoo database in:\n" -" Sales > Configuration > Address Book > Localization > Import NUTS 2013" -msgstr "" - diff --git a/base_location_nuts/i18n/es.po b/base_location_nuts/i18n/es.po index 6a27ad51f..86f6ef3ca 100644 --- a/base_location_nuts/i18n/es.po +++ b/base_location_nuts/i18n/es.po @@ -1,21 +1,23 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_location_nuts -# +# # Translators: msgid "" msgstr "" "Project-Id-Version: partner-contact (8.0)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-10-09 15:48+0000\n" -"PO-Revision-Date: 2015-10-06 13:57+0000\n" +"POT-Creation-Date: 2015-12-30 17:07+0100\n" +"PO-Revision-Date: 2015-12-30 17:11+0100\n" "Last-Translator: OCA Transbot \n" -"Language-Team: Spanish (http://www.transifex.com/oca/OCA-partner-contact-8-0/language/es/)\n" +"Language-Team: Spanish (http://www.transifex.com/oca/OCA-partner-contact-8-0/" +"language/es/)\n" +"Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Language: es\n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.8.5\n" #. module: base_location_nuts #: view:nuts.import:base_location_nuts.nuts_import_form @@ -23,7 +25,7 @@ msgid "Cancel" msgstr "Cancelar" #. module: base_location_nuts -#: field:res.partner.nuts,children:0 +#: field:res.partner.nuts,child_ids:0 msgid "Children" msgstr "Hijos" @@ -33,6 +35,7 @@ msgid "Code" msgstr "Código" #. module: base_location_nuts +#: model:ir.model,name:base_location_nuts.model_res_country #: view:res.partner.nuts:base_location_nuts.view_res_partner_nuts_filter #: field:res.partner.nuts,country_id:0 msgid "Country" @@ -97,6 +100,21 @@ msgstr "Importar NUTS 2013 desde RAMON" msgid "Import NUTS items from European RAMON service" msgstr "Importar regiones NUTS desde el servicio europeo RAMON" +#. module: base_location_nuts +#: help:res.country,region_label:0 +msgid "Label for the region NUTS category." +msgstr "Etiqueta para la categoría región NUTS." + +#. module: base_location_nuts +#: help:res.country,state_label:0 +msgid "Label for the state NUTS category." +msgstr "Etiqueta para la categoría estado NUTS." + +#. module: base_location_nuts +#: help:res.country,substate_label:0 +msgid "Label for the substate NUTS category." +msgstr "Etiqueta para la categoría subestado NUTS." + #. module: base_location_nuts #: field:nuts.import,write_uid:0 field:res.partner.nuts,write_uid:0 msgid "Last Updated by" @@ -113,18 +131,38 @@ msgstr "Última actualización en" msgid "Level" msgstr "Nivel" +#. module: base_location_nuts +#: help:res.country,region_level:0 +msgid "Level for the region NUTS category." +msgstr "Nivel para la categoría región NUTS." + +#. module: base_location_nuts +#: help:res.country,state_level:0 +msgid "Level for the state NUTS category." +msgstr "Nivel para la categoría estado NUTS." + +#. module: base_location_nuts +#: help:res.country,substate_level:0 +msgid "Level for the substate NUTS category." +msgstr "Nivel para la categoría subestado NUTS." + +#. module: base_location_nuts +#: view:res.country:base_location_nuts.view_country_form +msgid "NUTS" +msgstr "NUTS" + #. module: base_location_nuts #: model:ir.model,name:base_location_nuts.model_res_partner_nuts #: view:res.partner.nuts:base_location_nuts.res_partner_nuts_form msgid "NUTS Item" -msgstr "Región NUTS" +msgstr "Objeto NUTS" #. module: base_location_nuts #: model:ir.actions.act_window,name:base_location_nuts.res_partner_nuts_action #: model:ir.ui.menu,name:base_location_nuts.res_partner_nuts_menu #: view:res.partner.nuts:base_location_nuts.res_partner_nuts_tree msgid "NUTS Items" -msgstr "Regiones NUTS" +msgstr "Objetos NUTS" #. module: base_location_nuts #: field:res.partner.nuts,name:0 @@ -152,13 +190,24 @@ msgid "Partner" msgstr "Empresa" #. module: base_location_nuts -#: code:addons/base_location_nuts/models/res_partner.py:34 +#: code:addons/base_location_nuts/models/res_partner.py:22 +#: code:addons/base_location_nuts/models/res_partner.py:32 #: view:res.partner:base_location_nuts.view_res_partner_filter_nuts -#: field:res.partner,region:0 +#: field:res.partner,region_id:0 #, python-format msgid "Region" msgstr "Región" +#. module: base_location_nuts +#: field:res.country,region_label:0 +msgid "Region label" +msgstr "Etiqueta de región" + +#. module: base_location_nuts +#: field:res.country,region_level:0 +msgid "Region level" +msgstr "Nivel de región" + #. module: base_location_nuts #: view:res.partner:base_location_nuts.view_res_partner_filter_nuts msgid "Salesperson" @@ -175,13 +224,34 @@ msgid "State" msgstr "Provincia" #. module: base_location_nuts -#: code:addons/base_location_nuts/models/res_partner.py:35 +#: field:res.country,state_label:0 +msgid "State label" +msgstr "Etiqueta de estado" + +#. module: base_location_nuts +#: field:res.country,state_level:0 +msgid "State level" +msgstr "Nivel de estado" + +#. module: base_location_nuts +#: code:addons/base_location_nuts/models/res_partner.py:25 +#: code:addons/base_location_nuts/models/res_partner.py:33 #: view:res.partner:base_location_nuts.view_res_partner_filter_nuts -#: field:res.partner,substate:0 +#: field:res.partner,substate_id:0 #, python-format msgid "Substate" msgstr "Estado" +#. module: base_location_nuts +#: field:res.country,substate_label:0 +msgid "Substate label" +msgstr "Etiqueta de subestado" + +#. module: base_location_nuts +#: field:res.country,substate_level:0 +msgid "Substate level" +msgstr "Nivel de subestado" + #. module: base_location_nuts #: view:nuts.import:base_location_nuts.nuts_import_form msgid "" @@ -190,7 +260,13 @@ msgid "" " Updating or creating new NUTS entries if not\n" " found already in the system, and DELETING MISSING\n" " ENTRIES from new downloaded file." -msgstr "Este asistente descargará la última version de\n NUTS 2013 desde el servicio de matadatos europeo RAMON.\n Actualizando o creando nuevas regiones NUTS si no\n las encuentra en el sistemma, y BORRANDO LAS QUE NO ENCUENTRE\n en el nuevo fichero descargado." +msgstr "" +"Este asistente descargará la última version de\n" +" NUTS 2013 desde el servicio de metadatos europeo RAMON.\n" +" Actualizando o creando nuevas regiones NUTS si no\n" +" las encuentra en el sistema, y BORRANDO LAS QUE NO " +"ENCUENTRE\n" +" en el nuevo fichero descargado." #. module: base_location_nuts #: code:addons/base_location_nuts/wizard/nuts_import.py:97 @@ -208,5 +284,10 @@ msgstr "Usted puede importar NUTS desde el servicion europeo RAMON." msgid "" "You must click at import wizard to populate NUTS items\n" " in Odoo database in:\n" -" Sales > Configuration > Address Book > Localization > Import NUTS 2013" -msgstr "Debes clicar en el asistente de importación para crear las\n las regiones NUTS en la base de datos de Odoo, en el menú:\n Ventas > Configuración > Libreta de direcciones > Localización > Importar NUTS 2013" +" Sales > Configuration > Address Book > Localization > Import NUTS " +"2013" +msgstr "" +"Debes clicar en el asistente de importación para crear las\n" +" las regiones NUTS en la base de datos de Odoo, en el menú:\n" +" Ventas > Configuración > Libreta de direcciones > Localización > " +"Importar NUTS 2013" diff --git a/base_location_nuts/images/new_fields.png b/base_location_nuts/images/new_fields.png new file mode 100644 index 000000000..24f235bf5 Binary files /dev/null and b/base_location_nuts/images/new_fields.png differ diff --git a/base_location_nuts/models/__init__.py b/base_location_nuts/models/__init__.py index a88f82ad0..2a172bcaa 100644 --- a/base_location_nuts/models/__init__.py +++ b/base_location_nuts/models/__init__.py @@ -1,7 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################## -# For copyright and license notices, see __openerp__.py file in root directory -############################################################################## +# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import res_partner_nuts -from . import res_partner +from . import ( + res_country, + res_partner_nuts, + res_partner, +) diff --git a/base_location_nuts/models/res_country.py b/base_location_nuts/models/res_country.py new file mode 100644 index 000000000..e82947561 --- /dev/null +++ b/base_location_nuts/models/res_country.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields + + +class ResCountry(models.Model): + _inherit = "res.country" + + state_level = fields.Integer( + help="Level for the state NUTS category.") diff --git a/base_location_nuts/models/res_partner.py b/base_location_nuts/models/res_partner.py index 904580980..c5ddae6e7 100644 --- a/base_location_nuts/models/res_partner.py +++ b/base_location_nuts/models/res_partner.py @@ -1,61 +1,122 @@ # -*- coding: utf-8 -*- -############################################################################## -# For copyright and license notices, see __openerp__.py file in root directory -############################################################################## +# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api -from openerp.tools.translate import _ -import collections - - -def dict_recursive_update(d, u): - for k, v in u.iteritems(): - if isinstance(v, collections.Mapping): - r = dict_recursive_update(d.get(k, {}), v) - d[k] = r - else: - d[k] = u[k] - return d class ResPartner(models.Model): _inherit = 'res.partner' - region = fields.Many2one(comodel_name='res.partner.nuts', - string="Region") - substate = fields.Many2one(comodel_name='res.partner.nuts', - string="Substate") - lbl_region = fields.Char(compute='_labels_get') - lbl_substate = fields.Char(compute='_labels_get') + nuts1_id = fields.Many2one( + comodel_name='res.partner.nuts', domain=[('level', '=', 1)], + string="NUTS L1") + nuts2_id = fields.Many2one( + comodel_name='res.partner.nuts', domain=[('level', '=', 2)], + string="NUTS L2", oldname="region") + nuts3_id = fields.Many2one( + comodel_name='res.partner.nuts', domain=[('level', '=', 3)], + string="NUTS L3", oldname="substate") + nuts4_id = fields.Many2one( + comodel_name='res.partner.nuts', domain=[('level', '=', 4)], + string="NUTS L4") + + @api.multi + def _onchange_nuts(self, level): + field = self["nuts%d_id" % level] + country_id = field.country_id.id + state_id = field.state_id.id + if country_id and self.country_id.id != country_id: + self.country_id = country_id + if state_id and self.state_id.id != state_id: + self.state_id = state_id + if (level - 1) > 0: + parent_id = field.parent_id.id + if parent_id: + parent_field = 'nuts%d_id' % (level - 1) + if self[parent_field].id != parent_id: + self[parent_field] = parent_id + result = dict() + if country_id and level < 4: + result['domain'] = dict() + while level < 4: + parent_field = 'nuts%d_id' % level + domain_field = 'nuts%d_id' % (level + 1) + parent_id = self[parent_field].id + if parent_id: + result['domain'][domain_field] = [ + ('parent_id', '=', parent_id), + ] + level += 1 + return result + + @api.multi + @api.onchange('nuts4_id') + def _onchange_nuts4_id(self): + return self._onchange_nuts(4) - @api.one - @api.depends('country_id') - def _labels_get(self): - self.lbl_region = _('Region') - self.lbl_substate = _('Substate') + @api.multi + @api.onchange('nuts3_id') + def _onchange_nuts3_id(self): + return self._onchange_nuts(3) + + @api.multi + @api.onchange('nuts2_id') + def _onchange_nuts2_id(self): + return self._onchange_nuts(2) + + @api.multi + @api.onchange('nuts1_id') + def _onchange_nuts1_id(self): + return self._onchange_nuts(1) + + @api.multi + @api.onchange('country_id') + def _onchange_country_id(self): + """Sensible values and domains for related fields.""" + fields = ['state_id', 'nuts1_id', 'nuts2_id', 'nuts3_id', 'nuts4_id'] + country_domain = ([('country_id', '=', self.country_id.id)] + if self.country_id else []) + domain = dict() + for field in fields: + if self.country_id and self[field].country_id != self.country_id: + self[field] = False + domain[field] = list(country_domain) # Using list() to copy + fields.remove('state_id') + for field in fields: + level = int(field[:5][-1]) + if level: + domain[field].append(('level', '=', level)) + if self.country_id: + nuts1 = self.env['res.partner.nuts'].search([ + ('level', '=', 1), + ('country_id', '=', self.country_id.id), + ], limit=1) + if self.nuts1_id.id != nuts1.id: + self.nuts1_id = nuts1.id + return { + 'domain': domain, + } @api.multi def onchange_state(self, state_id): result = super(ResPartner, self).onchange_state(state_id) - if not state_id: - changes = { - 'domain': { - 'substate': [], - 'region': [], - }, - 'value': { - 'substate': False, - 'region': False, - } - } - dict_recursive_update(result, changes) + state = self.env['res.country.state'].browse(state_id) + if state.country_id.state_level: + nuts_state = self.env['res.partner.nuts'].search([ + ('level', '=', state.country_id.state_level), + ('state_id', '=', state.id) + ], limit=1) + if nuts_state: + field = 'nuts%d_id' % state.country_id.state_level + result.setdefault("value", dict()) + result['value'][field] = nuts_state.id return result - @api.onchange('substate', 'region') - def onchange_substate_or_region(self): - result = {'domain': {}} - if not self.substate: - result['domain']['substate'] = [] - if not self.region: - result['domain']['region'] = [] - return result + @api.model + def _address_fields(self): + fields = super(ResPartner, self)._address_fields() + if fields: + fields += ['nuts1_id', 'nuts2_id', 'nuts3_id', 'nuts4_id'] + return fields diff --git a/base_location_nuts/models/res_partner_nuts.py b/base_location_nuts/models/res_partner_nuts.py index f8e62f20b..cea22cf92 100644 --- a/base_location_nuts/models/res_partner_nuts.py +++ b/base_location_nuts/models/res_partner_nuts.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# For copyright and license notices, see __openerp__.py file in root directory -############################################################################## +# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields @@ -24,7 +24,10 @@ class ResPartnerNuts(models.Model): # Parent hierarchy parent_id = fields.Many2one(comodel_name='res.partner.nuts', ondelete='restrict') - children = fields.One2many(comodel_name='res.partner.nuts', - inverse_name='parent_id') + child_ids = fields.One2many( + 'res.partner.nuts', + 'parent_id', + "Children", + oldname="children") parent_left = fields.Integer('Parent Left', select=True) parent_right = fields.Integer('Parent Right', select=True) diff --git a/base_location_nuts/views/res_country_view.xml b/base_location_nuts/views/res_country_view.xml new file mode 100644 index 000000000..cb451f78b --- /dev/null +++ b/base_location_nuts/views/res_country_view.xml @@ -0,0 +1,25 @@ + + + + + + + + NUTS fields + res.country + + + + + + + + + + + + + + diff --git a/base_location_nuts/views/res_partner_nuts_view.xml b/base_location_nuts/views/res_partner_nuts_view.xml index 877edd243..3ecad6631 100644 --- a/base_location_nuts/views/res_partner_nuts_view.xml +++ b/base_location_nuts/views/res_partner_nuts_view.xml @@ -1,4 +1,7 @@ + diff --git a/base_location_nuts/views/res_partner_view.xml b/base_location_nuts/views/res_partner_view.xml index 55192e41c..9bf0cd81b 100644 --- a/base_location_nuts/views/res_partner_view.xml +++ b/base_location_nuts/views/res_partner_view.xml @@ -1,4 +1,7 @@ + @@ -8,48 +11,16 @@ -
- -
-
- -
-
- -
-
- -
+ + + +
-
- -
-
- -
-
- -
-
- -
+ + + +
@@ -60,19 +31,27 @@ - - + + + + - - + + context="{'group_by': 'nuts2_id'}"/> + +
-
\ No newline at end of file +
diff --git a/base_location_nuts/wizard/__init__.py b/base_location_nuts/wizard/__init__.py index 1f9d83bcf..66654141f 100644 --- a/base_location_nuts/wizard/__init__.py +++ b/base_location_nuts/wizard/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# For copyright and license notices, see __openerp__.py file in root directory -############################################################################## +# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import nuts_import diff --git a/base_location_nuts/wizard/nuts_import.py b/base_location_nuts/wizard/nuts_import.py index e63f908fe..2073bceff 100644 --- a/base_location_nuts/wizard/nuts_import.py +++ b/base_location_nuts/wizard/nuts_import.py @@ -1,18 +1,16 @@ # -*- coding: utf-8 -*- -############################################################################## -# For copyright and license notices, see __openerp__.py file in root directory -############################################################################## +# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, api, _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError import requests import re import logging from lxml import etree from collections import OrderedDict -from pprint import pformat - logger = logging.getLogger(__name__) @@ -93,7 +91,7 @@ class NutsImport(models.TransientModel): else: logger.debug("xpath = '%s', not found" % field_xpath) if field_required and not value: - raise Warning( + raise UserError( _('Value not found for mandatory field %s' % k)) item[k] = value return item @@ -114,11 +112,11 @@ class NutsImport(models.TransientModel): try: res_request = requests.get(url) except Exception, e: - raise Warning( + raise UserError( _('Got an error when trying to download the file: %s.') % str(e)) if res_request.status_code != requests.codes.ok: - raise Warning( + raise UserError( _('Got an error %d when trying to download the file %s.') % (res_request.status_code, url)) logger.info('Download successfully %d bytes' % @@ -127,7 +125,7 @@ class NutsImport(models.TransientModel): pattern = re.compile(r'^.*<\?xml', re.DOTALL) content_fixed = re.sub(pattern, ' GB (United Kingdom) self._countries['EL'] = self._countries['GR'] self._countries['UK'] = self._countries['GB'] - logger.info('_load_countries = %s' % pformat(self._countries)) @api.model def state_mapping(self, data, node): @@ -184,13 +181,14 @@ class NutsImport(models.TransientModel): nuts_to_delete = nuts_model.search( [('country_id', 'in', [x.id for x in self._countries.values()])]) # Download NUTS in english, create or update - logger.info('Import NUTS 2013 English') + logger.info('Importing NUTS 2013 English') xmlcontent = self._download_nuts() dom = etree.fromstring(xmlcontent) for node in dom.iter('Item'): - logger.info('Reading level=%s, id=%s' % - (node.get('idLevel', 'N/A'), - node.get('id', 'N/A'))) + logger.debug( + 'Reading level=%s, id=%s', + node.get('idLevel', 'N/A'), + node.get('id', 'N/A')) nuts = self.create_or_update_nuts(node) if nuts and nuts in nuts_to_delete: nuts_to_delete -= nuts diff --git a/base_location_nuts/wizard/nuts_import_view.xml b/base_location_nuts/wizard/nuts_import_view.xml index 6acd7bdbc..1c023c834 100644 --- a/base_location_nuts/wizard/nuts_import_view.xml +++ b/base_location_nuts/wizard/nuts_import_view.xml @@ -1,4 +1,7 @@ +