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.

62 lines
1.8 KiB

  1. from datetime import timedelta
  2. from pytz import timezone, utc
  3. from odoo import models, fields, api
  4. class SurveySurvey(models.Model):
  5. _inherit = "survey.survey"
  6. @api.model
  7. def cron_close_passed_deadline_survey(self):
  8. to_close = self.search(
  9. [
  10. ("deadline", "!=", False),
  11. ("deadline", "<", fields.Date.today()),
  12. ("auto_close", "=", True),
  13. ]
  14. )
  15. if to_close:
  16. to_close.action_archive()
  17. deadline = fields.Date(
  18. string="Deadline",
  19. copy=False,
  20. tracking=True,
  21. help="The day after date at 00:00 will be set as default answer deadline on survey sharing.",
  22. )
  23. auto_close = fields.Boolean(
  24. string="Auto closing",
  25. help="If checked, this survey will be automatically closed after the deadline.",
  26. )
  27. active = fields.Boolean(
  28. tracking=True,
  29. )
  30. def action_send_survey(self):
  31. self.ensure_one()
  32. action = super(SurveySurvey, self).action_send_survey()
  33. action["context"].update(
  34. {
  35. "default_deadline": timezone(self.env.user.tz)
  36. .localize(
  37. fields.Datetime.to_datetime(fields.Date.to_string(self.deadline))
  38. + timedelta(days=1)
  39. )
  40. .astimezone(utc),
  41. }
  42. )
  43. return action
  44. @api.onchange("deadline")
  45. def onchange_deadline(self):
  46. self.ensure_one()
  47. if not self.deadline and self.auto_close:
  48. self.auto_close = False
  49. def _track_subtype(self, init_values):
  50. self.ensure_one()
  51. if "active" in init_values:
  52. return self.env.ref(
  53. "survey_deadline_autoclose.mail_message_subtype_survey_closing"
  54. )
  55. return super(SurveySurvey, self)._track_subtype(init_values)