diff --git a/partner_sector/README.rst b/partner_sector/README.rst index 7e3c39ccf..684172e7e 100644 --- a/partner_sector/README.rst +++ b/partner_sector/README.rst @@ -54,6 +54,7 @@ Contributors * Antonio Espinosa * Javier Iniesta * Vicent Cubells +* Pedro M. Baeza Maintainer ---------- diff --git a/partner_sector/__openerp__.py b/partner_sector/__openerp__.py index 9640be0fe..27eec15a6 100644 --- a/partner_sector/__openerp__.py +++ b/partner_sector/__openerp__.py @@ -6,7 +6,7 @@ { "name": "Partner Sector", "summary": "Add partner sectors", - "version": "9.0.1.0.0", + "version": "9.0.1.0.1", "category": "Customer Relationship Management", "website": "http://www.tecnativa.com", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/partner_sector/i18n/.gitkeep b/partner_sector/i18n/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/partner_sector/i18n/partner_sector.pot b/partner_sector/i18n/partner_sector.pot deleted file mode 100644 index 2262ae02a..000000000 --- a/partner_sector/i18n/partner_sector.pot +++ /dev/null @@ -1,106 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * partner_sector -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-12-17 13:49+0000\n" -"PO-Revision-Date: 2015-12-17 13:49+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: partner_sector -#: field:res.partner.sector,child_ids:0 -msgid "Children" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,create_uid:0 -msgid "Created by" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,create_date:0 -msgid "Created on" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,id:0 -msgid "ID" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,write_uid:0 -msgid "Last Updated by" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,write_date:0 -msgid "Last Updated on" -msgstr "" - -#. module: partner_sector -#: field:res.partner,sector_id:0 -msgid "Main Sector" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,name:0 -msgid "Name" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,parent_left:0 -msgid "Parent Left" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,parent_right:0 -msgid "Parent Right" -msgstr "" - -#. module: partner_sector -#: field:res.partner.sector,parent_id:0 -msgid "Parent id" -msgstr "" - -#. module: partner_sector -#: model:ir.model,name:partner_sector.model_res_partner -msgid "Partner" -msgstr "" - -#. module: partner_sector -#: view:res.partner:partner_sector.view_res_partner_filter_sector -msgid "Salesperson" -msgstr "" - -#. module: partner_sector -#: field:res.partner,secondary_sector_ids:0 -msgid "Secondary Sectors" -msgstr "" - -#. module: partner_sector -#: model:ir.model,name:partner_sector.model_res_partner_sector -#: view:res.partner:partner_sector.view_partner_form_sector -#: view:res.partner:partner_sector.view_res_partner_filter_sector -msgid "Sector" -msgstr "" - -#. module: partner_sector -#: model:ir.actions.act_window,name:partner_sector.res_partner_sector_action -#: model:ir.ui.menu,name:partner_sector.menu_res_partner_sector -#: view:res.partner.sector:partner_sector.res_partner_sector_tree_view -msgid "Sectors" -msgstr "" - -#. module: partner_sector -#: code:addons/partner_sector/models/res_partner.py:21 -#, python-format -msgid "The main sector must be different from the secondary sectors." -msgstr "" diff --git a/partner_sector/models/res_partner_sector.py b/partner_sector/models/res_partner_sector.py index d1861a145..bf34c0637 100644 --- a/partner_sector/models/res_partner_sector.py +++ b/partner_sector/models/res_partner_sector.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- # © 2015 Antiun Ingenieria S.L. - Javier Iniesta # © 2016 Tecnativa S.L. - Vicent Cubells +# © 2016 Tecnativa S.L. - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api +from openerp import _, api, fields, exceptions, models class ResPartnerSector(models.Model): @@ -33,3 +34,9 @@ class ResPartnerSector(models.Model): return res return [(cat.id, " / ".join(reversed(get_names(cat)))) for cat in self] + + @api.constrains('parent_id') + def _check_parent_id(self): + if not self._check_recursion(): + raise exceptions.ValidationError( + _('Error! You cannot create recursive sectors.')) diff --git a/partner_sector/tests/__init__.py b/partner_sector/tests/__init__.py index 74a487558..844191e01 100644 --- a/partner_sector/tests/__init__.py +++ b/partner_sector/tests/__init__.py @@ -3,4 +3,4 @@ # © 2016 Tecnativa S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import test_res_partner +from . import test_res_partner_sector diff --git a/partner_sector/tests/test_res_partner.py b/partner_sector/tests/test_res_partner.py deleted file mode 100644 index c18b35ff3..000000000 --- a/partner_sector/tests/test_res_partner.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2015 Antiun Ingenieria S.L. - Javier Iniesta -# © 2016 Tecnativa S.L. - Vicent Cubells -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp.tests.common import TransactionCase -from openerp.exceptions import ValidationError - - -class TestResPartner(TransactionCase): - - def test_check_sectors(self): - sector = self.env['res.partner.sector'].create({'name': 'Test'}) - with self.assertRaises(ValidationError): - self.env['res.partner'].create( - {'name': 'Test', 'sector_id': sector.id, - 'secondary_sector_ids': [(4, sector.id)]}) diff --git a/partner_sector/tests/test_res_partner_sector.py b/partner_sector/tests/test_res_partner_sector.py new file mode 100644 index 000000000..16b830ee0 --- /dev/null +++ b/partner_sector/tests/test_res_partner_sector.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# © 2016 Tecnativa S.L. - Vicent Cubells +# © 2016 Tecnativa S.L. - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common +from openerp.exceptions import ValidationError + + +class TestResPartnerSector(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestResPartnerSector, cls).setUpClass() + cls.Sector = cls.env['res.partner.sector'] + cls.sector_main = cls.Sector.create({ + 'name': 'Test', + }) + cls.sector_child = cls.Sector.create({ + 'name': 'Test child', + 'parent_id': cls.sector_main.id, + }) + + def test_check_sectors(self): + with self.assertRaises(ValidationError): + self.env['res.partner'].create({ + 'name': 'Test', + 'sector_id': self.sector_main.id, + 'secondary_sector_ids': [(4, self.sector_main.id)], + }) + + def test_check_recursion(self): + with self.assertRaises(ValidationError): + self.sector_main.parent_id = self.sector_child.id + + def test_name(self): + self.assertEqual( + self.sector_child.name_get()[0][1], + "Test / Test child", + )