diff --git a/base_location_nuts/README.rst b/base_location_nuts/README.rst index 18c380523..ee531fb41 100644 --- a/base_location_nuts/README.rst +++ b/base_location_nuts/README.rst @@ -44,6 +44,13 @@ 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. +To configure lables and levels per country, you should install a l10n module, +but if you want to do it manually, you need to: + +* Have *Sales / Responsible permissions*. +* Go to *Sales > Configuration > Address Book > Localization > Countries*. +* Choose one. +* Use the fields under the *NUTS* section. Usage ===== @@ -56,7 +63,6 @@ in order to allow to assign them to partner object. :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/134/{branch} - Bug Tracker =========== @@ -74,6 +80,7 @@ Contributors * Rafael Blasco * Antonio Espinosa +* Jairo Llopis Maintainer ---------- @@ -88,4 +95,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/__manifest__.py b/base_location_nuts/__manifest__.py index c22f40521..ee617bd1b 100644 --- a/base_location_nuts/__manifest__.py +++ b/base_location_nuts/__manifest__.py @@ -24,11 +24,12 @@ { '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', diff --git a/base_location_nuts/i18n/es.po b/base_location_nuts/i18n/es.po index 1bbee771d..4fadf2138 100644 --- a/base_location_nuts/i18n/es.po +++ b/base_location_nuts/i18n/es.po @@ -1,19 +1,23 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * base_location_nuts +# * base_location_nuts # +# Translators: msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: partner-contact (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" +"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: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \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 @@ -21,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" @@ -31,37 +35,36 @@ 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" msgstr "País" #. module: base_location_nuts -#: field:nuts.import,create_uid:0 -#: field:res.partner.nuts,create_uid:0 +#: field:nuts.import,create_uid:0 field:res.partner.nuts,create_uid:0 msgid "Created by" msgstr "Creado por" #. module: base_location_nuts -#: field:nuts.import,create_date:0 -#: field:res.partner.nuts,create_date:0 +#: field:nuts.import,create_date:0 field:res.partner.nuts,create_date:0 msgid "Created on" msgstr "Creado en" #. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:149 +#: code:addons/base_location_nuts/wizard/nuts_import.py:130 #, python-format msgid "Downloaded file is not a valid XML file" msgstr "El fichero descargado no es un fichero XML válido" #. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:141 +#: code:addons/base_location_nuts/wizard/nuts_import.py:122 #, python-format msgid "Got an error %d when trying to download the file %s." msgstr "Error %d al intentar descargar el fichero %s." #. module: base_location_nuts -#: code:addons/base_location_nuts/wizard/nuts_import.py:137 +#: code:addons/base_location_nuts/wizard/nuts_import.py:118 #, python-format msgid "Got an error when trying to download the file: %s." msgstr "Error al intentar descargar el fichero: %s." @@ -72,8 +75,7 @@ msgid "Group By" msgstr "Agrupar por" #. module: base_location_nuts -#: field:nuts.import,id:0 -#: field:res.partner.nuts,id:0 +#: field:nuts.import,id:0 field:res.partner.nuts,id:0 msgid "ID" msgstr "ID" @@ -99,14 +101,27 @@ msgid "Import NUTS items from European RAMON service" msgstr "Importar regiones NUTS desde el servicio europeo RAMON" #. module: base_location_nuts -#: field:nuts.import,write_uid:0 -#: field:res.partner.nuts,write_uid:0 +#: 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" msgstr "Última actualización por" #. module: base_location_nuts -#: field:nuts.import,write_date:0 -#: field:res.partner.nuts,write_date:0 +#: field:nuts.import,write_date:0 field:res.partner.nuts,write_date:0 msgid "Last Updated on" msgstr "Última actualización en" @@ -116,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 @@ -155,13 +190,24 @@ msgid "Partner" msgstr "Empresa" #. module: base_location_nuts -#: code:addons/base_location_nuts/models/res_partner.py:53 +#: 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" @@ -178,28 +224,52 @@ msgid "State" msgstr "Provincia" #. module: base_location_nuts -#: code:addons/base_location_nuts/models/res_partner.py:54 +#: 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 "This wizard will download the lastest version of\n" +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 "Este asistente descargará la última version de\n" +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" +" las encuentra en el sistemma, 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:116 +#: code:addons/base_location_nuts/wizard/nuts_import.py:97 #, python-format msgid "Value not found for mandatory field %s" msgstr "El valor no se ha encontrado para el campo obligatorio %s" @@ -211,10 +281,13 @@ msgstr "Usted puede importar NUTS desde el servicion europeo RAMON." #. 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" +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" +" 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" - +" Ventas > Configuración > Libreta de direcciones > Localización > " +"Importar NUTS 2013" 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..6d5e50dc0 --- /dev/null +++ b/base_location_nuts/models/res_country.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 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): + """Add labels corresponding to each country. + + These stay empty in this base module, and should be filled by l10n ones. + """ + _inherit = "res.country" + + state_label = fields.Char( + translate=True, + help="Label for the state NUTS category.") + substate_label = fields.Char( + translate=True, + help="Label for the substate NUTS category.") + region_label = fields.Char( + translate=True, + help="Label for the region NUTS category.") + state_level = fields.Integer( + help="Level for the state NUTS category.") + substate_level = fields.Integer( + help="Level for the substate NUTS category.") + region_level = fields.Integer( + help="Level for the region NUTS category.") diff --git a/base_location_nuts/models/res_partner.py b/base_location_nuts/models/res_partner.py index 904580980..fef97cd9a 100644 --- a/base_location_nuts/models/res_partner.py +++ b/base_location_nuts/models/res_partner.py @@ -5,57 +5,69 @@ 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') + region_id = fields.Many2one( + 'res.partner.nuts', + "Region", + oldname="region") + substate_id = fields.Many2one( + 'res.partner.nuts', + "Substate", + oldname="substate") + lbl_region = fields.Char( + default=_("Region"), + compute='_labels_get') + lbl_substate = fields.Char( + default=_("Substate"), + compute='_labels_get') - @api.one + @api.multi @api.depends('country_id') def _labels_get(self): - self.lbl_region = _('Region') - self.lbl_substate = _('Substate') + for s in self: + s.lbl_region = s.country_id.region_label or _('Region') + s.lbl_substate = s.country_id.substate_label or _('Substate') + + @api.multi + @api.onchange("substate_id") + def _onchange_substate_id(self): + if self.substate_id.country_id: + self.country_id = self.substate_id.country_id + return dict() @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) - 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.onchange("region_id") + def _onchange_region_id(self): + if self.region_id.country_id: + self.country_id = self.region_id.country_id + return dict() + + @api.multi + @api.onchange("country_id") + def _onchange_country_id(self): + """Sensible values and domains for related fields.""" + fields = {"state", "region", "substate"} + country_domain = ([("country_id", "=", self.country_id.id)] + if self.country_id else []) + + domain = dict() + for field in fields: + field += "_id" + 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") + for field in fields: + level = self.country_id["%s_level" % field] + field += "_id" + if level: + domain[field].append(("level", "=", level)) + + return { + "domain": domain, + } diff --git a/base_location_nuts/models/res_partner_nuts.py b/base_location_nuts/models/res_partner_nuts.py index f8e62f20b..c17c7a86d 100644 --- a/base_location_nuts/models/res_partner_nuts.py +++ b/base_location_nuts/models/res_partner_nuts.py @@ -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..57ddccaa2 --- /dev/null +++ b/base_location_nuts/views/res_country_view.xml @@ -0,0 +1,33 @@ + + + + + + + + NUTS fields + res.country + + + + + + + + + + + + + + + + + + + + + + + diff --git a/base_location_nuts/views/res_partner_view.xml b/base_location_nuts/views/res_partner_view.xml index 55192e41c..38cd98eee 100644 --- a/base_location_nuts/views/res_partner_view.xml +++ b/base_location_nuts/views/res_partner_view.xml @@ -13,7 +13,7 @@
- @@ -23,7 +23,7 @@
- @@ -35,7 +35,7 @@
- @@ -45,7 +45,7 @@
- @@ -60,19 +60,19 @@ - - + + + context="{'group_by': 'region_id'}"/> + context="{'group_by': 'substate_id'}"/> - \ No newline at end of file +