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.

53 lines
1.8 KiB

  1. from odoo import models, fields, api, _
  2. from odoo.exceptions import UserError
  3. class SurveySurvey(models.Model):
  4. _inherit = 'survey.survey'
  5. @api.model
  6. def close_deadline_survey(self):
  7. deadline = self.search([
  8. ('date_deadline', '!=', False),
  9. ('date_deadline', '<', fields.Date.today()),
  10. ])
  11. to_close = deadline.filtered('auto_close')
  12. if to_close:
  13. to_close.action_close_survey()
  14. for survey in deadline - to_close:
  15. survey.message_post(subtype='survey_deadline_autoclose.mail_message_subtype_survey_deadline')
  16. date_deadline = fields.Date(string="Deadline", copy=False, track_visibility='onchange')
  17. auto_close = fields.Boolean(string="Auto close", default=False, help="If checked, the survey will be closed automatically when deadline is overpassed.", track_visibility='onchange')
  18. # ACTIONS
  19. @api.multi
  20. def action_send_survey(self):
  21. self.ensure_one()
  22. action = super(SurveySurvey, self).action_send_survey()
  23. action['context'].update({
  24. 'default_date_deadline': self.date_deadline,
  25. })
  26. return action
  27. @api.multi
  28. def action_close_survey(self):
  29. stage = self.env['survey.stage'].search([('closed', '=', True)], limit=1)
  30. if not stage:
  31. raise UserError(_("No \"closed\" status found, the requested operation is impossible."))
  32. self.write({
  33. 'stage_id': stage.id
  34. })
  35. for survey in self:
  36. survey.message_post(subtype='survey_deadline_autoclose.mail_message_subtype_survey_closed')
  37. # ONCHANGES
  38. @api.onchange('date_deadline')
  39. def onchange_is_template(self):
  40. self.ensure_one()
  41. if not self.date_deadline:
  42. self.auto_close = False
  43. elif not self.auto_close:
  44. self.auto_close = True