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.

46 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. )
  13. class ResPartnerDepartment(models.Model):
  14. _name = 'res.partner.department'
  15. _order = "parent_path"
  16. _parent_order = "name"
  17. _parent_store = True
  18. _description = "Department"
  19. name = fields.Char(
  20. required=True,
  21. translate=True
  22. )
  23. parent_id = fields.Many2one(
  24. "res.partner.department",
  25. "Parent department",
  26. ondelete='restrict'
  27. )
  28. child_ids = fields.One2many(
  29. "res.partner.department",
  30. "parent_id",
  31. "Child departments"
  32. )
  33. parent_path = fields.Char(index=True)
  34. @api.constrains('parent_id')
  35. def _check_parent_id(self):
  36. if not self._check_recursion():
  37. raise ValidationError(
  38. _('Error! You cannot create recursive departments.'))