Browse Source

[MIG] partner_contact_department v11 to v12

pull/695/head
Nikul-Chaudhary 6 years ago
parent
commit
cc97b00d09
  1. 4
      partner_contact_department/__manifest__.py
  2. 8
      partner_contact_department/migrations/12.0.1.0.0/post-migration.py
  3. 19
      partner_contact_department/models/res_partner.py
  4. 1
      partner_contact_department/readme/CONTRIBUTORS.rst
  5. 19
      partner_contact_department/tests/test_recursion.py

4
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',

8
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()

19
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):

1
partner_contact_department/readme/CONTRIBUTORS.rst

@ -4,3 +4,4 @@
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Nikul Chaudhary <nikulchaudhary2112@gmail.com>

19
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})
Loading…
Cancel
Save