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.

25 lines
787 B

  1. # Copyright 2019 Creu Blanca
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, models, _
  4. from odoo.tools.safe_eval import safe_eval
  5. from odoo.exceptions import UserError
  6. class TierValidation(models.AbstractModel):
  7. _inherit = 'tier.validation'
  8. @api.multi
  9. def evaluate_formula_tier(self, tier):
  10. try:
  11. res = safe_eval(tier.python_code, globals_dict={'rec': self})
  12. except Exception as error:
  13. raise UserError(_(
  14. "Error evaluating tier validation conditions.\n %s") % error)
  15. return res
  16. @api.multi
  17. def evaluate_tier(self, tier):
  18. if tier.definition_type == 'formula':
  19. return self.evaluate_formula_tier(tier)
  20. return super().evaluate_tier(tier)