diff --git a/partner_contact_department/__manifest__.py b/partner_contact_department/__manifest__.py index 2c2dd1ff1..b0fa03cec 100644 --- a/partner_contact_department/__manifest__.py +++ b/partner_contact_department/__manifest__.py @@ -6,12 +6,12 @@ { 'name': 'Partner Contact Department', "summary": "Assign contacts to departments", - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Customer Relationship Management', 'author': 'Tecnativa, ' 'Odoo Community Association (OCA)', "license": "AGPL-3", - 'website': 'http://www.tecnativa.com', + 'website': 'https://github.com/OCA/partner-contact', "application": False, 'depends': [ 'contacts', diff --git a/partner_contact_department/migrations/12.0.1.0.0/post-migration.py b/partner_contact_department/migrations/12.0.1.0.0/post-migration.py new file mode 100644 index 000000000..c16403627 --- /dev/null +++ b/partner_contact_department/migrations/12.0.1.0.0/post-migration.py @@ -0,0 +1,8 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + env['res.partner.department']._parent_store_compute() diff --git a/partner_contact_department/models/res_partner.py b/partner_contact_department/models/res_partner.py index e2271f3cc..84423d360 100644 --- a/partner_contact_department/models/res_partner.py +++ b/partner_contact_department/models/res_partner.py @@ -12,27 +12,32 @@ class ResPartner(models.Model): department_id = fields.Many2one( "res.partner.department", "Department", - oldname="department") + oldname="department" + ) class ResPartnerDepartment(models.Model): _name = 'res.partner.department' - _order = "parent_left" + _order = "parent_path" _parent_order = "name" _parent_store = True _description = "Department" - name = fields.Char(required=True, translate=True) + name = fields.Char( + required=True, + translate=True + ) parent_id = fields.Many2one( "res.partner.department", "Parent department", - ondelete='restrict') + ondelete='restrict' + ) child_ids = fields.One2many( "res.partner.department", "parent_id", - "Child departments") - parent_left = fields.Integer(index=True) - parent_right = fields.Integer(index=True) + "Child departments" + ) + parent_path = fields.Char(index=True) @api.constrains('parent_id') def _check_parent_id(self): diff --git a/partner_contact_department/readme/CONTRIBUTORS.rst b/partner_contact_department/readme/CONTRIBUTORS.rst index 32f276341..2e8045a46 100644 --- a/partner_contact_department/readme/CONTRIBUTORS.rst +++ b/partner_contact_department/readme/CONTRIBUTORS.rst @@ -4,3 +4,4 @@ * Jairo Llopis * Vicent Cubells * David Vidal +* Nikul Chaudhary diff --git a/partner_contact_department/tests/test_recursion.py b/partner_contact_department/tests/test_recursion.py index fc37be866..bcda4aadb 100644 --- a/partner_contact_department/tests/test_recursion.py +++ b/partner_contact_department/tests/test_recursion.py @@ -12,19 +12,18 @@ class TestRecursion(common.SavepointCase): 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 - )) + cls.dpt1 = cls.department_obj.create({'name': 'Dpt. 1'}) + cls.dpt2 = cls.department_obj.create({ + 'name': 'Dep. 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 - )) + self.dpt3 = self.department_obj.create({ + 'name': 'Dep. 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})