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.

35 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. _order = 'name'
  9. alias = fields.Char(
  10. 'Alias',
  11. help='The complete path to the field where you can specify an '
  12. 'alias on the a step as field:alias'
  13. )
  14. @api.constrains('alias', 'name')
  15. def _check_alias(self):
  16. for rec in self:
  17. if not rec.alias:
  18. continue
  19. names = rec.name.split('/')
  20. names_with_alias = rec.alias.split('/')
  21. if len(names) != len(names_with_alias):
  22. raise ValidationError(
  23. _("Name and Alias must have the same hierarchy depth"))
  24. for name, name_with_alias in zip(names, names_with_alias):
  25. field_name = name_with_alias.split(':')[0]
  26. if name != field_name:
  27. raise ValidationError(
  28. _("The alias must reference the same field as in "
  29. "name '%s' not in '%s'") % (name, name_with_alias)
  30. )