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.

37 lines
1.3 KiB

  1. # Copyright 2017 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import ValidationError
  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. )
  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. _(
  28. "The alias must reference the same field as in "
  29. "name '%s' not in '%s'"
  30. )
  31. % (name, name_with_alias)
  32. )