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. # Copyright 2019 Tecnativa - Cristina Martin R.
  6. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  7. from odoo import api, exceptions, fields, models, _
  8. class ResPartnerIndustry(models.Model):
  9. _inherit = 'res.partner.industry'
  10. _order = "parent_path"
  11. _parent_order = "name"
  12. _parent_store = True
  13. name = fields.Char(required=True)
  14. parent_id = fields.Many2one(comodel_name='res.partner.industry',
  15. ondelete='restrict')
  16. child_ids = fields.One2many(comodel_name='res.partner.industry',
  17. inverse_name='parent_id',
  18. string="Children")
  19. parent_path = fields.Char(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.'))