You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2015 Tecnativa S.L. - Jairo Llopis
  3. # © 2016 Tecnativa S.L. - Vicent Cubells
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import models, fields, api, _
  6. from odoo.exceptions import ValidationError
  7. class ResPartner(models.Model):
  8. _inherit = 'res.partner'
  9. department_id = fields.Many2one(
  10. "res.partner.department",
  11. "Department",
  12. oldname="department")
  13. class ResPartnerDepartment(models.Model):
  14. _name = 'res.partner.department'
  15. _order = "parent_left"
  16. _parent_order = "name"
  17. _parent_store = True
  18. _description = "Department"
  19. name = fields.Char(required=True, translate=True)
  20. parent_id = fields.Many2one(
  21. "res.partner.department",
  22. "Parent department",
  23. ondelete='restrict')
  24. child_ids = fields.One2many(
  25. "res.partner.department",
  26. "parent_id",
  27. "Child departments")
  28. parent_left = fields.Integer(index=True)
  29. parent_right = fields.Integer(index=True)
  30. @api.constrains('parent_id')
  31. def _check_parent_id(self):
  32. if not self._check_recursion():
  33. raise ValidationError(
  34. _('Error! You cannot create recursive departments.'))