David Vidal
8 years ago
committed by
Jairo Llopis
21 changed files with 210 additions and 168 deletions
-
20base_location_nuts/README.rst
-
3base_location_nuts/__init__.py
-
35base_location_nuts/__manifest__.py
-
2base_location_nuts/i18n/de.po
-
2base_location_nuts/i18n/es.po
-
2base_location_nuts/i18n/fi.po
-
2base_location_nuts/i18n/it.po
-
2base_location_nuts/i18n/sl.po
-
11base_location_nuts/models/__init__.py
-
8base_location_nuts/models/res_country.py
-
66base_location_nuts/models/res_partner.py
-
29base_location_nuts/models/res_partner_nuts.py
-
3base_location_nuts/tests/__init__.py
-
90base_location_nuts/tests/test_base_location_nuts.py
-
10base_location_nuts/views/res_country_view.xml
-
11base_location_nuts/views/res_partner_nuts_view.xml
-
11base_location_nuts/views/res_partner_view.xml
-
3base_location_nuts/wizard/__init__.py
-
56base_location_nuts/wizard/nuts_import.py
-
11base_location_nuts/wizard/nuts_import_view.xml
-
1pylint-odoo
@ -1,7 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# For copyright and license notices, see __openerp__.py file in root directory |
|||
############################################################################## |
|||
|
|||
from . import models |
|||
from . import wizard |
@ -1,10 +1,5 @@ |
|||
# -*- 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 . import ( |
|||
res_country, |
|||
res_partner_nuts, |
|||
res_partner, |
|||
) |
|||
from . import res_country |
|||
from . import res_partner |
|||
from . import res_partner_nuts |
@ -1,33 +1,32 @@ |
|||
# -*- 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). |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com> |
|||
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from openerp import models, fields |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class ResPartnerNuts(models.Model): |
|||
_name = 'res.partner.nuts' |
|||
_order = "parent_left" |
|||
_parent_order = "name" |
|||
_order = 'parent_left' |
|||
_parent_order = 'name' |
|||
_parent_store = True |
|||
_description = "NUTS Item" |
|||
_description = 'NUTS Item' |
|||
|
|||
# NUTS fields |
|||
level = fields.Integer(required=True) |
|||
code = fields.Char(required=True) |
|||
name = fields.Char(required=True, translate=True) |
|||
country_id = fields.Many2one(comodel_name='res.country', string="Country", |
|||
country_id = fields.Many2one(comodel_name='res.country', string='Country', |
|||
required=True) |
|||
state_id = fields.Many2one(comodel_name='res.country.state', |
|||
string='State') |
|||
# Parent hierarchy |
|||
parent_id = fields.Many2one(comodel_name='res.partner.nuts', |
|||
ondelete='restrict') |
|||
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) |
|||
child_ids = fields.One2many(comodel_name='res.partner.nuts', |
|||
inverse_name='parent_id', string='Children', |
|||
oldname='children') |
|||
parent_left = fields.Integer('Parent Left', index=True) |
|||
parent_right = fields.Integer('Parent Right', index=True) |
@ -0,0 +1,3 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
from . import test_base_location_nuts |
@ -0,0 +1,90 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 David Vidal <david.vidal@tecnativa.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo.tests import common |
|||
from odoo.exceptions import UserError |
|||
|
|||
|
|||
class TestBaseLocationNuts(common.SavepointCase): |
|||
@classmethod |
|||
def setUpClass(cls): |
|||
super(TestBaseLocationNuts, cls).setUpClass() |
|||
cls.importer = cls.env['nuts.import'] |
|||
cls.importer.run_import() # loads nuts |
|||
cls.country_1 = cls.env['res.country'].search([('code', '=', 'ES')]) |
|||
cls.country_2 = cls.env['res.country'].search([('code', '=', 'PT')]) |
|||
cls.nuts1_2 = cls.env[ |
|||
'res.partner.nuts'].search([('code', '=', 'PT')]) |
|||
cls.nuts2_1 = cls.env[ |
|||
'res.partner.nuts'].search([('code', '=', 'ES2')]) |
|||
cls.nuts3_1 = cls.env[ |
|||
'res.partner.nuts'].search([('code', '=', 'ES24')]) |
|||
cls.nuts4_1 = cls.env[ |
|||
'res.partner.nuts'].search([('code', '=', 'ES243')]) |
|||
cls.nuts4_2 = cls.env[ |
|||
'res.partner.nuts'].search([('code', '=', 'ES300')]) |
|||
cls.partner = cls.env['res.partner'].create({ |
|||
'name': 'Test partner', |
|||
'country_id': cls.country_1.id, |
|||
}) |
|||
cls.state_1 = cls.env['res.country.state'].create({ |
|||
'name': 'Zaragoza Test', |
|||
'code': 'ZT', |
|||
'country_id': cls.country_1.id, |
|||
}) |
|||
cls.nuts4_1.state_id = cls.state_1 |
|||
cls.state_2 = cls.env['res.country.state'].create({ |
|||
'name': 'Madrid Test', |
|||
'code': 'MT', |
|||
'country_id': cls.country_1.id, |
|||
}) |
|||
cls.nuts4_2.state_id = cls.state_2 |
|||
cls.country_1.state_level = 4 |
|||
|
|||
def test_onchange_nuts_country(self): |
|||
self.partner.nuts1_id = self.nuts1_2 |
|||
self.partner._onchange_nuts1_id() |
|||
self.assertEqual(self.partner.country_id, self.nuts1_2.country_id) |
|||
|
|||
def test_onchange_nuts(self): |
|||
self.partner.country_id = self.country_2 |
|||
self.partner._onchange_country_id() |
|||
self.assertEqual(self.partner.nuts1_id.country_id, |
|||
self.partner.country_id) |
|||
self.partner.nuts4_id = self.nuts4_1 |
|||
self.partner._onchange_nuts4_id() |
|||
self.assertEqual(self.partner.country_id, |
|||
self.country_1) |
|||
self.assertEqual(self.partner.nuts3_id, self.nuts3_1) |
|||
self.partner._onchange_nuts3_id() |
|||
self.assertEqual(self.partner.nuts2_id, self.nuts2_1) |
|||
self.partner._onchange_nuts2_id() |
|||
self.assertEqual(self.partner.nuts1_id.country_id, self.country_1) |
|||
self.partner.country_id = self.country_2 |
|||
self.partner._onchange_country_id() |
|||
self.assertEqual(self.partner.country_id, self.nuts1_2.country_id) |
|||
self.assertFalse(self.partner.nuts2_id) |
|||
self.assertFalse(self.partner.nuts3_id) |
|||
self.assertFalse(self.partner.nuts4_id) |
|||
|
|||
def test_onchange_states(self): |
|||
self.partner.state_id = self.state_2 |
|||
self.partner.onchange_state_id_base_location_nuts() |
|||
self.assertEqual(self.state_2, self.partner.nuts4_id.state_id) |
|||
self.partner.state_id = self.state_1 |
|||
self.partner.onchange_state_id_base_location_nuts() |
|||
self.assertEqual(self.state_1, self.partner.nuts4_id.state_id) |
|||
self.partner._onchange_nuts4_id() |
|||
self.assertEqual(self.partner.nuts3_id, self.nuts3_1) |
|||
self.partner._onchange_nuts3_id() |
|||
self.assertEqual(self.partner.nuts2_id, self.nuts2_1) |
|||
self.partner._onchange_nuts2_id() |
|||
self.assertEqual(self.partner.nuts1_id.country_id, self.country_1) |
|||
|
|||
def test_download_exceptions(self): |
|||
""" Tests download exceptions """ |
|||
with self.assertRaises(UserError): |
|||
self.importer._download_nuts(url_base='htttt://test.com') |
|||
with self.assertRaises(UserError): |
|||
self.importer._download_nuts(url_base='http://ec.europa.eu/_404') |
@ -1,6 +1,3 @@ |
|||
# -*- 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 . import nuts_import |
Write
Preview
Loading…
Cancel
Save
Reference in new issue