Browse Source
Merge pull request #233 from Yajo/nuts
Merge pull request #233 from Yajo/nuts
[8.0][IMP][base_location_nuts] Simplify, fix some bugspull/254/head
Rafael Blasco
9 years ago
15 changed files with 323 additions and 370 deletions
-
30base_location_nuts/README.rst
-
6base_location_nuts/__openerp__.py
-
214base_location_nuts/i18n/base_location_nuts.pot
-
113base_location_nuts/i18n/es.po
-
BINbase_location_nuts/images/new_fields.png
-
13base_location_nuts/models/__init__.py
-
13base_location_nuts/models/res_country.py
-
153base_location_nuts/models/res_partner.py
-
13base_location_nuts/models/res_partner_nuts.py
-
25base_location_nuts/views/res_country_view.xml
-
3base_location_nuts/views/res_partner_nuts_view.xml
-
73base_location_nuts/views/res_partner_view.xml
-
6base_location_nuts/wizard/__init__.py
-
28base_location_nuts/wizard/nuts_import.py
-
3base_location_nuts/wizard/nuts_import_view.xml
@ -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 "" |
|
||||
|
|
After Width: 582 | Height: 215 | Size: 17 KiB |
@ -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, |
||||
|
) |
@ -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.") |
@ -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.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 |
@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 |
@ -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> |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue