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.

45 lines
1.5 KiB

  1. # Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
  2. # Copyright 2017 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
  4. from odoo import api, fields, models
  5. class CustomInfoOption(models.Model):
  6. _description = "Available options for a custom property"
  7. _name = "custom.info.option"
  8. _order = "name"
  9. name = fields.Char(index=True, translate=True, required=True)
  10. property_ids = fields.Many2many(
  11. comodel_name="custom.info.property",
  12. string="Properties",
  13. help="Properties where this option is enabled.",
  14. )
  15. value_ids = fields.One2many(
  16. comodel_name="custom.info.value",
  17. inverse_name="value_id",
  18. string="Values",
  19. help="Values that have set this option.",
  20. )
  21. template_id = fields.Many2one(
  22. comodel_name="custom.info.template",
  23. string="Additional template",
  24. help="Additional template to be applied to the owner if this option "
  25. "is chosen.",
  26. )
  27. @api.multi
  28. def check_access_rule(self, operation):
  29. """You access an option if you access at least one property."""
  30. last_error = None
  31. for prop in self.mapped("property_ids"):
  32. try:
  33. prop.check_access_rule(operation)
  34. return
  35. except Exception as err:
  36. last_error = err
  37. pass
  38. if last_error:
  39. raise last_error
  40. return super().check_access_rule(operation)