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.5 KiB

  1. # Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
  2. # Copyright 2016 Tecnativa S.L. - Vicent Cubells
  3. # Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
  4. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from odoo import api, exceptions, fields, models, _
  7. class ResPartnerIndustry(models.Model):
  8. _inherit = 'res.partner.industry'
  9. _order = "parent_left"
  10. _parent_order = "name"
  11. _parent_store = True
  12. name = fields.Char(required=True)
  13. parent_id = fields.Many2one(comodel_name='res.partner.industry',
  14. ondelete='restrict')
  15. child_ids = fields.One2many(comodel_name='res.partner.industry',
  16. inverse_name='parent_id',
  17. string="Children")
  18. parent_left = fields.Integer('Parent Left', index=True)
  19. parent_right = fields.Integer('Parent Right', index=True)
  20. @api.multi
  21. def name_get(self):
  22. def get_names(cat):
  23. """ Return the list [cat.name, cat.parent_id.name, ...] """
  24. res = []
  25. while cat:
  26. res.insert(0, cat.name)
  27. cat = cat.parent_id
  28. return res
  29. return [(cat.id, " / ".join(get_names(cat))) for cat in self]
  30. @api.constrains('parent_id')
  31. def _check_parent_id(self):
  32. if not self._check_recursion():
  33. raise exceptions.ValidationError(
  34. _('Error! You cannot create recursive industries.'))