Browse Source

Merge pull request #233 from Yajo/nuts

[8.0][IMP][base_location_nuts] Simplify, fix some bugs
pull/254/head
Rafael Blasco 9 years ago
parent
commit
7595397aed
  1. 28
      base_location_nuts/README.rst
  2. 6
      base_location_nuts/__openerp__.py
  3. 214
      base_location_nuts/i18n/base_location_nuts.pot
  4. 111
      base_location_nuts/i18n/es.po
  5. BIN
      base_location_nuts/images/new_fields.png
  6. 13
      base_location_nuts/models/__init__.py
  7. 13
      base_location_nuts/models/res_country.py
  8. 153
      base_location_nuts/models/res_partner.py
  9. 13
      base_location_nuts/models/res_partner_nuts.py
  10. 25
      base_location_nuts/views/res_country_view.xml
  11. 3
      base_location_nuts/views/res_partner_nuts_view.xml
  12. 71
      base_location_nuts/views/res_partner_view.xml
  13. 6
      base_location_nuts/wizard/__init__.py
  14. 28
      base_location_nuts/wizard/nuts_import.py
  15. 3
      base_location_nuts/wizard/nuts_import_view.xml

28
base_location_nuts/README.rst

@ -7,28 +7,22 @@ NUTS Regions
This module allows to import NUTS locations. 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 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 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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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 Bug Tracker
=========== ===========
@ -74,6 +67,7 @@ Contributors
* Rafael Blasco <rafabn@antiun.com> * Rafael Blasco <rafabn@antiun.com>
* Antonio Espinosa <antonioea@antiun.com> * Antonio Espinosa <antonioea@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.com>
Maintainer Maintainer
---------- ----------

6
base_location_nuts/__openerp__.py

@ -24,16 +24,20 @@
{ {
'name': 'NUTS Regions', 'name': 'NUTS Regions',
'category': 'Localisation/Europe', 'category': 'Localisation/Europe',
'version': '8.0.1.0.0',
'version': '8.0.2.0.0',
'depends': [ 'depends': [
'base', 'base',
], ],
'data': [ 'data': [
'views/res_country_view.xml',
'views/res_partner_nuts_view.xml', 'views/res_partner_nuts_view.xml',
'views/res_partner_view.xml', 'views/res_partner_view.xml',
'wizard/nuts_import_view.xml', 'wizard/nuts_import_view.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
], ],
'images': [
'images/new_fields.png',
],
'author': 'Antiun Ingeniería S.L., ' 'author': 'Antiun Ingeniería S.L., '
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',
'website': 'http://www.antiun.com', 'website': 'http://www.antiun.com',

214
base_location_nuts/i18n/base_location_nuts.pot

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

111
base_location_nuts/i18n/es.po

@ -7,15 +7,17 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: partner-contact (8.0)\n" "Project-Id-Version: partner-contact (8.0)\n"
"Report-Msgid-Bugs-To: \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 <transbot@odoo-community.org>\n" "Last-Translator: OCA Transbot <transbot@odoo-community.org>\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" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\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" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.5\n"
#. module: base_location_nuts #. module: base_location_nuts
#: view:nuts.import:base_location_nuts.nuts_import_form #: view:nuts.import:base_location_nuts.nuts_import_form
@ -23,7 +25,7 @@ msgid "Cancel"
msgstr "Cancelar" msgstr "Cancelar"
#. module: base_location_nuts #. module: base_location_nuts
#: field:res.partner.nuts,children:0
#: field:res.partner.nuts,child_ids:0
msgid "Children" msgid "Children"
msgstr "Hijos" msgstr "Hijos"
@ -33,6 +35,7 @@ msgid "Code"
msgstr "Código" msgstr "Código"
#. module: base_location_nuts #. 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 #: view:res.partner.nuts:base_location_nuts.view_res_partner_nuts_filter
#: field:res.partner.nuts,country_id:0 #: field:res.partner.nuts,country_id:0
msgid "Country" msgid "Country"
@ -97,6 +100,21 @@ msgstr "Importar NUTS 2013 desde RAMON"
msgid "Import NUTS items from European RAMON service" msgid "Import NUTS items from European RAMON service"
msgstr "Importar regiones NUTS desde el servicio europeo RAMON" 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 #. module: base_location_nuts
#: field:nuts.import,write_uid:0 field:res.partner.nuts,write_uid:0 #: field:nuts.import,write_uid:0 field:res.partner.nuts,write_uid:0
msgid "Last Updated by" msgid "Last Updated by"
@ -113,18 +131,38 @@ msgstr "Última actualización en"
msgid "Level" msgid "Level"
msgstr "Nivel" 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 #. module: base_location_nuts
#: model:ir.model,name:base_location_nuts.model_res_partner_nuts #: model:ir.model,name:base_location_nuts.model_res_partner_nuts
#: view:res.partner.nuts:base_location_nuts.res_partner_nuts_form #: view:res.partner.nuts:base_location_nuts.res_partner_nuts_form
msgid "NUTS Item" msgid "NUTS Item"
msgstr "Región NUTS"
msgstr "Objeto NUTS"
#. module: base_location_nuts #. module: base_location_nuts
#: model:ir.actions.act_window,name:base_location_nuts.res_partner_nuts_action #: 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 #: model:ir.ui.menu,name:base_location_nuts.res_partner_nuts_menu
#: view:res.partner.nuts:base_location_nuts.res_partner_nuts_tree #: view:res.partner.nuts:base_location_nuts.res_partner_nuts_tree
msgid "NUTS Items" msgid "NUTS Items"
msgstr "Regiones NUTS"
msgstr "Objetos NUTS"
#. module: base_location_nuts #. module: base_location_nuts
#: field:res.partner.nuts,name:0 #: field:res.partner.nuts,name:0
@ -152,13 +190,24 @@ msgid "Partner"
msgstr "Empresa" msgstr "Empresa"
#. module: base_location_nuts #. 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 #: view:res.partner:base_location_nuts.view_res_partner_filter_nuts
#: field:res.partner,region:0
#: field:res.partner,region_id:0
#, python-format #, python-format
msgid "Region" msgid "Region"
msgstr "Región" 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 #. module: base_location_nuts
#: view:res.partner:base_location_nuts.view_res_partner_filter_nuts #: view:res.partner:base_location_nuts.view_res_partner_filter_nuts
msgid "Salesperson" msgid "Salesperson"
@ -175,13 +224,34 @@ msgid "State"
msgstr "Provincia" msgstr "Provincia"
#. module: base_location_nuts #. 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 #: view:res.partner:base_location_nuts.view_res_partner_filter_nuts
#: field:res.partner,substate:0
#: field:res.partner,substate_id:0
#, python-format #, python-format
msgid "Substate" msgid "Substate"
msgstr "Estado" 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 #. module: base_location_nuts
#: view:nuts.import:base_location_nuts.nuts_import_form #: view:nuts.import:base_location_nuts.nuts_import_form
msgid "" msgid ""
@ -190,7 +260,13 @@ msgid ""
" Updating or creating new NUTS entries if not\n" " Updating or creating new NUTS entries if not\n"
" found already in the system, and DELETING MISSING\n" " found already in the system, and DELETING MISSING\n"
" ENTRIES from new downloaded file." " 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 #. module: base_location_nuts
#: code:addons/base_location_nuts/wizard/nuts_import.py:97 #: 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 "" msgid ""
"You must click at import wizard to populate NUTS items\n" "You must click at import wizard to populate NUTS items\n"
" in Odoo database in:\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"

BIN
base_location_nuts/images/new_fields.png

After

Width: 582  |  Height: 215  |  Size: 17 KiB

13
base_location_nuts/models/__init__.py

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*- # -*- 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,
)

13
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.")

153
base_location_nuts/models/res_partner.py

@ -1,61 +1,122 @@
# -*- coding: utf-8 -*- # -*- 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 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): class ResPartner(models.Model):
_inherit = 'res.partner' _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.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.one
@api.depends('country_id')
def _labels_get(self):
self.lbl_region = _('Region')
self.lbl_substate = _('Substate')
@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 @api.multi
def onchange_state(self, state_id): def onchange_state(self, state_id):
result = super(ResPartner, self).onchange_state(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 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

13
base_location_nuts/models/res_partner_nuts.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- 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 from openerp import models, fields
@ -24,7 +24,10 @@ class ResPartnerNuts(models.Model):
# Parent hierarchy # Parent hierarchy
parent_id = fields.Many2one(comodel_name='res.partner.nuts', parent_id = fields.Many2one(comodel_name='res.partner.nuts',
ondelete='restrict') 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_left = fields.Integer('Parent Left', select=True)
parent_right = fields.Integer('Parent Right', select=True) parent_right = fields.Integer('Parent Right', select=True)

25
base_location_nuts/views/res_country_view.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingeniería S.L. - Jairo Llopis
© 2015 Antiun Ingeniería S.L. - Antonio Espinosa
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<record id="view_country_form" model="ir.ui.view">
<field name="name">NUTS fields</field>
<field name="model">res.country</field>
<field name="inherit_id" ref="base.view_country_form"/>
<field name="arch" type="xml">
<xpath expr="/form">
<group name="nuts" string="NUTS">
<group>
<field name="state_level"/>
</group>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

3
base_location_nuts/views/res_partner_nuts_view.xml

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingeniería S.L. - Jairo Llopis
© 2015 Antiun Ingeniería S.L. - Antonio Espinosa
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp> <openerp>
<data> <data>

71
base_location_nuts/views/res_partner_view.xml

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingeniería S.L. - Jairo Llopis
© 2015 Antiun Ingeniería S.L. - Antonio Espinosa
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp> <openerp>
<data> <data>
@ -8,48 +11,16 @@
<field name="inherit_id" ref="base.view_partner_form"/> <field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//sheet/group//field[@name='country_id']/.." position="after"> <xpath expr="//sheet/group//field[@name='country_id']/.." position="after">
<div width="1%" cell-class="oe_form_group_cell_label"
attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="lbl_substate" class="oe_inline"/>
</div>
<div attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="substate"
class="oe_no_button"
options="{'no_open': True, 'no_create': True}"
attrs="{'readonly': [('use_parent_address','=',True)]}"/>
</div>
<div width="1%" cell-class="oe_form_group_cell_label"
attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="lbl_region" class="oe_inline"/>
</div>
<div attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="region"
class="oe_no_button"
options="{'no_open': True, 'no_create': True}"
attrs="{'readonly': [('use_parent_address','=',True)]}"/>
</div>
<field name="nuts1_id"/>
<field name="nuts2_id"/>
<field name="nuts3_id"/>
<field name="nuts4_id"/>
</xpath> </xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='country_id']/.." position="after"> <xpath expr="//field[@name='child_ids']/form//field[@name='country_id']/.." position="after">
<div width="1%" cell-class="oe_form_group_cell_label"
attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="lbl_substate" class="oe_inline"/>
</div>
<div attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="substate"
class="oe_no_button"
options="{'no_open': True, 'no_create': True}"
attrs="{'readonly': [('use_parent_address','=',True)]}"/>
</div>
<div width="1%" cell-class="oe_form_group_cell_label"
attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="lbl_region" class="oe_inline"/>
</div>
<div attrs="{'invisible': [('use_parent_address','=',True)]}">
<field name="region"
class="oe_no_button"
options="{'no_open': True, 'no_create': True}"
attrs="{'readonly': [('use_parent_address','=',True)]}"/>
</div>
<field name="nuts1_id"/>
<field name="nuts2_id"/>
<field name="nuts3_id"/>
<field name="nuts4_id"/>
</xpath> </xpath>
</field> </field>
</record> </record>
@ -60,16 +31,24 @@
<field name="inherit_id" ref="base.view_res_partner_filter"/> <field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="category_id" position="after"> <field name="category_id" position="after">
<field name="region"/>
<field name="substate"/>
<field name="nuts1_id"/>
<field name="nuts2_id"/>
<field name="nuts3_id"/>
<field name="nuts4_id"/>
</field> </field>
<filter string="Salesperson" position="after"> <filter string="Salesperson" position="after">
<filter string="Region"
<filter string="NUTS L1"
domain="[]" domain="[]"
context="{'group_by': 'region'}"/>
<filter string="Substate"
context="{'group_by': 'nuts1_id'}"/>
<filter string="NUTS L2"
domain="[]" domain="[]"
context="{'group_by': 'substate'}"/>
context="{'group_by': 'nuts2_id'}"/>
<filter string="NUTS L3"
domain="[]"
context="{'group_by': 'nuts3_id'}"/>
<filter string="NUTS L4"
domain="[]"
context="{'group_by': 'nuts4_id'}"/>
</filter> </filter>
</field> </field>
</record> </record>

6
base_location_nuts/wizard/__init__.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 from . import nuts_import

28
base_location_nuts/wizard/nuts_import.py

@ -1,18 +1,16 @@
# -*- coding: utf-8 -*- # -*- 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 import models, api, _
from openerp.exceptions import Warning
from openerp.exceptions import Warning as UserError
import requests import requests
import re import re
import logging import logging
from lxml import etree from lxml import etree
from collections import OrderedDict from collections import OrderedDict
from pprint import pformat
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -93,7 +91,7 @@ class NutsImport(models.TransientModel):
else: else:
logger.debug("xpath = '%s', not found" % field_xpath) logger.debug("xpath = '%s', not found" % field_xpath)
if field_required and not value: if field_required and not value:
raise Warning(
raise UserError(
_('Value not found for mandatory field %s' % k)) _('Value not found for mandatory field %s' % k))
item[k] = value item[k] = value
return item return item
@ -114,11 +112,11 @@ class NutsImport(models.TransientModel):
try: try:
res_request = requests.get(url) res_request = requests.get(url)
except Exception, e: except Exception, e:
raise Warning(
raise UserError(
_('Got an error when trying to download the file: %s.') % _('Got an error when trying to download the file: %s.') %
str(e)) str(e))
if res_request.status_code != requests.codes.ok: if res_request.status_code != requests.codes.ok:
raise Warning(
raise UserError(
_('Got an error %d when trying to download the file %s.') _('Got an error %d when trying to download the file %s.')
% (res_request.status_code, url)) % (res_request.status_code, url))
logger.info('Download successfully %d bytes' % logger.info('Download successfully %d bytes' %
@ -127,7 +125,7 @@ class NutsImport(models.TransientModel):
pattern = re.compile(r'^.*<\?xml', re.DOTALL) pattern = re.compile(r'^.*<\?xml', re.DOTALL)
content_fixed = re.sub(pattern, '<?xml', res_request.content) content_fixed = re.sub(pattern, '<?xml', res_request.content)
if not re.match(r'<\?xml', content_fixed): if not re.match(r'<\?xml', content_fixed):
raise Warning(_('Downloaded file is not a valid XML file'))
raise UserError(_('Downloaded file is not a valid XML file'))
return content_fixed return content_fixed
@api.model @api.model
@ -140,7 +138,6 @@ class NutsImport(models.TransientModel):
# UK => GB (United Kingdom) # UK => GB (United Kingdom)
self._countries['EL'] = self._countries['GR'] self._countries['EL'] = self._countries['GR']
self._countries['UK'] = self._countries['GB'] self._countries['UK'] = self._countries['GB']
logger.info('_load_countries = %s' % pformat(self._countries))
@api.model @api.model
def state_mapping(self, data, node): def state_mapping(self, data, node):
@ -184,13 +181,14 @@ class NutsImport(models.TransientModel):
nuts_to_delete = nuts_model.search( 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 # Download NUTS in english, create or update
logger.info('Import NUTS 2013 English')
logger.info('Importing NUTS 2013 English')
xmlcontent = self._download_nuts() xmlcontent = self._download_nuts()
dom = etree.fromstring(xmlcontent) dom = etree.fromstring(xmlcontent)
for node in dom.iter('Item'): 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) nuts = self.create_or_update_nuts(node)
if nuts and nuts in nuts_to_delete: if nuts and nuts in nuts_to_delete:
nuts_to_delete -= nuts nuts_to_delete -= nuts

3
base_location_nuts/wizard/nuts_import_view.xml

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingeniería S.L. - Jairo Llopis
© 2015 Antiun Ingeniería S.L. - Antonio Espinosa
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp> <openerp>
<data> <data>

Loading…
Cancel
Save