from datetime import timedelta as tdelta from odoo import models, fields, api, _ class SurveySurvey(models.Model): _inherit = "survey.survey" @api.model def cron_close_passed_deadline_survey(self): to_close = self.search( [ ("deadline", "!=", False), ("deadline", "<", fields.Date.today()), ] ) if to_close: # to_close.action_close_survey() to_close.action_archive() deadline = fields.Date( string="Deadline", copy=False, tracking=True, help="This survey will be automatically closed after this date.", ) active = fields.Boolean( tracking=True, ) def action_send_survey(self): self.ensure_one() action = super(SurveySurvey, self).action_send_survey() action["context"].update( { "default_deadline": self.deadline, } ) return action def _track_subtype(self, init_values): self.ensure_one() if "active" in init_values: return self.env.ref( "survey_deadline_autoclose.mail_message_subtype_survey_closing" ) return super(SurveySurvey, self)._track_subtype(init_values)