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.

41 lines
1.2 KiB

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