diff --git a/partner_contact_department/README.rst b/partner_contact_department/README.rst index f15fcdce0..85d5a154f 100644 --- a/partner_contact_department/README.rst +++ b/partner_contact_department/README.rst @@ -29,7 +29,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/134/8.0 + :target: https://runbot.odoo-community.org/runbot/134/9.0 Bug Tracker =========== @@ -37,11 +37,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed `feedback -`_. +help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -49,7 +45,7 @@ Credits Images ------ -* `Antiun Ingeniería S.L. `_: Icon. +* Odoo Community Association: `Icon `_. Contributors ------------ @@ -58,6 +54,7 @@ Contributors * Antonio Espinosa * Rafael Blasco * Jairo Llopis +* Vicent Cubells Maintainer ---------- diff --git a/partner_contact_department/__init__.py b/partner_contact_department/__init__.py index 9af8488e4..44de80558 100644 --- a/partner_contact_department/__init__.py +++ b/partner_contact_department/__init__.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza -# Copyright (c) 2015 Antiun Ingeniería S.L. (http://www.antiun.com) -# Antonio Espinosa -# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# © 2014-2015 Tecnativa S.L. - Jairo Llopis +# © 2016 Tecnativa S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/partner_contact_department/__openerp__.py b/partner_contact_department/__openerp__.py index a5323db87..080b98a55 100644 --- a/partner_contact_department/__openerp__.py +++ b/partner_contact_department/__openerp__.py @@ -1,21 +1,17 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza -# Copyright (c) 2015 Antiun Ingeniería S.L. (http://www.antiun.com) -# Antonio Espinosa -# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# © 2014-2015 Tecnativa S.L. - Jairo Llopis +# © 2016 Tecnativa S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Contact department', "summary": "Assign contacts to departments", - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Customer Relationship Management', - 'author': 'Serv. Tecnol. Avanzados - Pedro M. Baeza, ' - 'Antiun Ingeniería S.L., ' - "Odoo Community Association (OCA)", + 'author': 'Tecnativa, ' + 'Odoo Community Association (OCA)', "license": "AGPL-3", - 'website': 'http://www.antiun.com', + 'website': 'http://www.tecnativa.com', "application": False, 'depends': [ 'base', diff --git a/partner_contact_department/models/__init__.py b/partner_contact_department/models/__init__.py index 213b25fdc..6393dbaea 100644 --- a/partner_contact_department/models/__init__.py +++ b/partner_contact_department/models/__init__.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza -# Copyright (c) 2015 Antiun Ingeniería S.L. (http://www.antiun.com) -# Antonio Espinosa -# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# © 2014-2015 Tecnativa S.L. - Jairo Llopis +# © 2016 Tecnativa S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import res_partner diff --git a/partner_contact_department/models/res_partner.py b/partner_contact_department/models/res_partner.py index 5efdd40c0..94946ae8f 100644 --- a/partner_contact_department/models/res_partner.py +++ b/partner_contact_department/models/res_partner.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza -# Copyright (c) 2015 Antiun Ingeniería S.L. (http://www.antiun.com) -# Antonio Espinosa -# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# © 2014-2015 Tecnativa S.L. - Jairo Llopis +# © 2016 Tecnativa S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from openerp import models, fields, api, _ +from openerp.exceptions import ValidationError class ResPartner(models.Model): @@ -37,3 +35,9 @@ class ResPartnerDepartment(models.Model): oldname="children") parent_left = fields.Integer(index=True) parent_right = fields.Integer(index=True) + + @api.constrains('parent_id') + def _check_parent_id(self): + if not self._check_recursion(): + raise ValidationError( + _('Error! You cannot create recursive departments.')) diff --git a/partner_contact_department/tests/__init__.py b/partner_contact_department/tests/__init__.py new file mode 100644 index 000000000..7630da7d4 --- /dev/null +++ b/partner_contact_department/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0). + +from . import test_recursion diff --git a/partner_contact_department/tests/test_recursion.py b/partner_contact_department/tests/test_recursion.py new file mode 100644 index 000000000..90204dd0b --- /dev/null +++ b/partner_contact_department/tests/test_recursion.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# © 2016 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0). +from openerp.tests import common +from openerp.exceptions import ValidationError + + +class TestRecursion(common.SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestRecursion, cls).setUpClass() + cls.department_obj = cls.env['res.partner.department'] + + # Instances + cls.dpt1 = cls.department_obj.create(vals=dict(name='Dpt. 1')) + cls.dpt2 = cls.department_obj.create( + vals=dict( + name='Dpt. 2', + parent_id=cls.dpt1.id + )) + + def test_recursion(self): + """ Testing recursion """ + self.dpt3 = self.department_obj.create(vals=dict( + name='Dpt. 3', + parent_id=self.dpt2.id + )) + # Creating a parent's child department using dpt1. + with self.assertRaises(ValidationError): + self.dpt1.write(vals={'parent_id': self.dpt3.id}) diff --git a/partner_contact_department/views/res_partner_department_view.xml b/partner_contact_department/views/res_partner_department_view.xml index f7aae91f9..f07ab520c 100644 --- a/partner_contact_department/views/res_partner_department_view.xml +++ b/partner_contact_department/views/res_partner_department_view.xml @@ -1,47 +1,44 @@ - + - - + - - Departments - res.partner.department - form - tree - + + Departments + res.partner.department + form + tree + - - CRM department tree - res.partner.department - - - - - - - - - - CRM department form - res.partner.department - -
- + + CRM department tree + res.partner.department + + - - -
-
-
+ + + + + + CRM department form + res.partner.department + +
+ + + + + +
+
+
- + -
-
+ diff --git a/partner_contact_department/views/res_partner_view.xml b/partner_contact_department/views/res_partner_view.xml index 108a2415e..e97e209a8 100644 --- a/partner_contact_department/views/res_partner_view.xml +++ b/partner_contact_department/views/res_partner_view.xml @@ -1,49 +1,47 @@ - + - - + - - Partner form with department - res.partner - - - - - - - - - - - + + Partner form with department + res.partner + + + + + + + + + + + - - Partner search with department - res.partner - - - - + + Partner search with department + res.partner + + + + + + + + - - - - - + - - +