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.

34 lines
1.2 KiB

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