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.

74 lines
2.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 years ago
4 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 years ago
4 years ago
  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=True)
  6. @api.multi
  7. def copy_data(self, default=None):
  8. data = super(SurveySurvey, self).copy_data(default)[0]
  9. default = dict(default or {})
  10. if (
  11. self.is_template
  12. and default.get("is_template", None) is False
  13. or not self.is_template
  14. and default.get("is_template", False)
  15. ):
  16. data.update({"title": self.title})
  17. return [data]
  18. # ACTIONS
  19. @api.multi
  20. def create_survey_from_template(self, default={}):
  21. self.ensure_one()
  22. if not self.is_template:
  23. raise UserError(
  24. _(
  25. 'You should use the "Copy" secondary action to duplicate a non-template survey.'
  26. )
  27. )
  28. default.update({"is_template": False})
  29. new_survey = self.copy(default=default)
  30. return {
  31. "type": "ir.actions.act_window",
  32. "res_model": "survey.survey",
  33. "view_type": "form",
  34. "view_mode": "form",
  35. "target": "current",
  36. "res_id": new_survey.id,
  37. }
  38. @api.multi
  39. def create_template_from_survey(self, default={}):
  40. self.ensure_one()
  41. if self.is_template:
  42. raise UserError(
  43. _(
  44. 'You should use the "Copy" secondary action to duplicate a survey template.'
  45. )
  46. )
  47. default.update({"is_template": True})
  48. new_survey = self.copy(default=default)
  49. return {
  50. "type": "ir.actions.act_window",
  51. "res_model": "survey.survey",
  52. "view_type": "form",
  53. "view_mode": "form",
  54. "target": "current",
  55. "res_id": new_survey.id,
  56. }
  57. @api.multi
  58. def action_send_survey(self):
  59. self.ensure_one()
  60. if self.is_template:
  61. raise UserError(
  62. _(
  63. "You cannot send a template survey, create a new survey from this template and you'll be able to share it."
  64. )
  65. )
  66. return super(SurveySurvey, self).action_send_survey()