Odoo modules related to surveys
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.

46 lines
1.6 KiB

  1. from odoo import models, fields, api, _
  2. from odoo.exceptions import UserError
  3. class SurveySurvey(models.Model):
  4. _inherit = 'survey.survey'
  5. is_template = fields.Boolean(string="Is a template", default=False, copy=False)
  6. @api.multi
  7. def copy_data(self, default=None):
  8. data = super(SurveySurvey, self).copy_data(default)[0]
  9. title = isinstance(default, dict) and default.get('title', False) or False
  10. if title:
  11. data['title'] = title
  12. elif _(" (Template)") in data['title']:
  13. data['title'] = data['title'].replace(_(" (Template)"), "")
  14. return [data]
  15. # ACTIONS
  16. @api.multi
  17. def create_survey_from_template(self, default=None):
  18. self.ensure_one()
  19. if not self.is_template:
  20. raise UserError(_("You should use the \"Copy\" secondary action to duplicate a non-template survey."))
  21. return self.copy(default=default)
  22. @api.multi
  23. def action_send_survey(self):
  24. self.ensure_one()
  25. if self.is_template:
  26. raise UserError(_("You cannot send a template survey, create a new survey from this template and you'll be able to share it."))
  27. return super(SurveySurvey, self).action_send_survey()
  28. # ONCHANGES
  29. @api.onchange('is_template')
  30. def onchange_is_template(self):
  31. if self.title:
  32. if self.is_template:
  33. if _("(Template)") not in self.title:
  34. self.title = self.title.strip() + _(" (Template)")
  35. else:
  36. if _(" (Template)") in self.title:
  37. self.title = self.title.replace(_(" (Template)"), "")