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.

33 lines
1.2 KiB

  1. # Copyright 2017 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.exceptions import ValidationError
  4. from odoo import api, fields, models, _
  5. class IrExportsLine(models.Model):
  6. _inherit = 'ir.exports.line'
  7. alias = fields.Char(
  8. 'Alias',
  9. help='The complete path to the field where you can specify an '
  10. 'alias on the a step as field:alias'
  11. )
  12. @api.constrains('alias', 'name')
  13. def _check_alias(self):
  14. for rec in self:
  15. if not rec.alias:
  16. continue
  17. names = rec.name.split('/')
  18. names_with_alias = rec.alias.split('/')
  19. if len(names) != len(names_with_alias):
  20. raise ValidationError(
  21. _("Name and Alias must have the same hierarchy depth"))
  22. for name, name_with_alias in zip(names, names_with_alias):
  23. field_name = name_with_alias.split(':')[0]
  24. if name != field_name:
  25. raise ValidationError(
  26. _("The alias must reference the same field as in "
  27. "name '%s' not in '%s'") % (name, name_with_alias)
  28. )