diff --git a/survey_deadline_autoclose/__manifest__.py b/survey_deadline_autoclose/__manifest__.py index f6f2572..b4bfa62 100644 --- a/survey_deadline_autoclose/__manifest__.py +++ b/survey_deadline_autoclose/__manifest__.py @@ -1,22 +1,23 @@ # -*- coding: utf-8 -*- # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). { - "name": "Auto-close survey on deadline", + "name": "Close survey on deadline", "version": "1.0.0", "summary": """ - Deadline date on surveys and auto-close option + Add deadline date on surveys to auto-close them. """, "description": """ - This module adds a deadline date on surveys and a checkbox to automatically close them with a planned action.""", + This module adds a deadline date on surveys and a cron task to close them when this date is passed.""", "author": "RemiFr82", - "contributors": "Sudokeys", + "contributors": "", + "maintainer": "RemiFr82", "website": "https://remifr82.me", "license": "LGPL-3", "category": "Marketing", - # "price": 0, + # "price": 5.0, # "currency": "EUR", "application": False, - "installable": False, + "installable": True, "auto_install": False, "pre_init_hook": "", "post_init_hook": "", @@ -31,10 +32,10 @@ "data/mail_message_subtype.xml", "views/survey_survey.xml", ], + "assets": {}, "css": [], "images": [], "js": [], "test": [], "demo": [], - "maintainer": "RemiFr82", } diff --git a/survey_deadline_autoclose/data/ir_cron.xml b/survey_deadline_autoclose/data/ir_cron.xml index f32dc7a..59f8554 100644 --- a/survey_deadline_autoclose/data/ir_cron.xml +++ b/survey_deadline_autoclose/data/ir_cron.xml @@ -1,20 +1,19 @@ - Close expired surveys - + code - model.with_context(cron=True).cron_close_deadline_survey() - - + model.with_context(cron=True).cron_close_passed_deadline_survey() + + 1 days - + -1 - + diff --git a/survey_deadline_autoclose/data/mail_message_subtype.xml b/survey_deadline_autoclose/data/mail_message_subtype.xml index 7902f5e..81c5d1b 100644 --- a/survey_deadline_autoclose/data/mail_message_subtype.xml +++ b/survey_deadline_autoclose/data/mail_message_subtype.xml @@ -2,22 +2,13 @@ - - Expired survey + + Closing survey.survey - - - - This survey has expired. - - - - Closed survey - survey.survey - - - - This survey is closed. + + + + Survey closing diff --git a/survey_deadline_autoclose/i18n/fr.po b/survey_deadline_autoclose/i18n/fr.po index 4965cba..b5c3199 100644 --- a/survey_deadline_autoclose/i18n/fr.po +++ b/survey_deadline_autoclose/i18n/fr.po @@ -1,14 +1,14 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * survey_deadline_autoclose +# * survey_deadline_autoclose # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 16.0-20230613\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-02-28 18:13+0000\n" -"PO-Revision-Date: 2023-02-28 18:13+0000\n" -"Last-Translator: <>\n" +"POT-Creation-Date: 2024-12-27 14:59+0000\n" +"PO-Revision-Date: 2024-12-27 14:59+0000\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -16,69 +16,35 @@ msgstr "" "Plural-Forms: \n" #. module: survey_deadline_autoclose -#: model:ir.model.fields,field_description:survey_deadline_autoclose.field_survey_survey__auto_close -msgid "Auto close" -msgstr "Clôture automatique" +#: model_terms:ir.ui.view,arch_db:survey_deadline_autoclose.survey_survey_view_kanban +msgid "" +"Deadline\n" +"
" +msgstr "" +"Échéance\n" +"
" #. module: survey_deadline_autoclose -#: model:mail.message.subtype,description:survey_deadline_autoclose.mail_message_subtype_survey_closed -msgid "This survey is closed." -msgstr "Ce sondage est clôturé." +#: model:ir.model.fields,field_description:survey_deadline_autoclose.field_survey_survey__active +msgid "Active" +msgstr "Actif" #. module: survey_deadline_autoclose #: model:ir.actions.server,name:survey_deadline_autoclose.cron_close_expired_surveys_ir_actions_server #: model:ir.cron,cron_name:survey_deadline_autoclose.cron_close_expired_surveys -#: model:ir.cron,name:survey_deadline_autoclose.cron_close_expired_surveys msgid "Close expired surveys" -msgstr "Clôture des sondages arrivés à échéance" - -#. module: survey_deadline_autoclose -#: model_terms:ir.ui.view,arch_db:survey_deadline_autoclose.survey_survey_form -msgid "Close survey" -msgstr "Clôturer ce sondage" +msgstr "Fermeture des sondages échus" #. module: survey_deadline_autoclose -#: model:mail.message.subtype,name:survey_deadline_autoclose.mail_message_subtype_survey_closed -msgid "Closed survey" -msgstr "Sondage clos" +#: model:mail.message.subtype,name:survey_deadline_autoclose.mail_message_subtype_survey_closing +msgid "Closing" +msgstr "Fermeture" #. module: survey_deadline_autoclose -#: model:ir.model.fields,field_description:survey_deadline_autoclose.field_survey_survey__date_deadline +#: model:ir.model.fields,field_description:survey_deadline_autoclose.field_survey_survey__deadline +#: model_terms:ir.ui.view,arch_db:survey_deadline_autoclose.survey_survey_view_search msgid "Deadline" -msgstr "Echéance" - -#. module: survey_deadline_autoclose -#: model_terms:ir.ui.view,arch_db:survey_deadline_autoclose.survey_survey_kanban -msgid "Expiration :" -msgstr "Échéance :" - -#. module: survey_deadline_autoclose -#: model_terms:ir.ui.view,arch_db:survey_deadline_autoclose.survey_survey_search -msgid "Expiration month" -msgstr "Mois d'échéance" - -#. module: survey_deadline_autoclose -#: model:mail.message.subtype,name:survey_deadline_autoclose.mail_message_subtype_survey_expired -msgid "Expired survey" -msgstr "Sondage expiré" - -#. module: survey_deadline_autoclose -#: model_terms:ir.ui.view,arch_db:survey_deadline_autoclose.survey_survey_search -msgid "Group By" -msgstr "Regrouper par" - -#. module: survey_deadline_autoclose -#: model:ir.model.fields,help:survey_deadline_autoclose.field_survey_survey__auto_close -msgid "If checked, the survey will be automatically closed when deadline is overpassed." -msgstr "Si coché, ce sondage sera automatiquement clôturé lorsque la date d'échéance sera dépassée." - -#. module: survey_deadline_autoclose -#: code:addons/survey_deadline_autoclose/models/survey_survey.py:65 -#, python-format -msgid "No \"closed\" stage found, the requested operation is impossible.\n" -"To fix this situation, you have to check \"Closed\" at least on one survey stage." -msgstr "Aucune étape \"Fermé\" trouvée, l'opération demandée est impossible.\n" -"Pour régler ce problème, vous devez cocher \"Fermé\" sur au moins une étape." +msgstr "Échéance" #. module: survey_deadline_autoclose #: model:ir.model,name:survey_deadline_autoclose.model_survey_survey @@ -86,29 +52,6 @@ msgid "Survey" msgstr "Sondage" #. module: survey_deadline_autoclose -#: code:addons/survey_deadline_autoclose/models/survey_survey.py:56 -#, python-format -msgid "Survey closing impossible" -msgstr "Clôture du sondage impossible" - -#. module: survey_deadline_autoclose -#: code:addons/survey_deadline_autoclose/models/survey_survey.py:57 -#, python-format -msgid "Survey should have been automatically closed but no \"closed\" stage was found, the requested operation was impossible to proceed.\n" -"To fix this situation, you have to check \"Closed\" at least on one survey stage." -msgstr "Ce sondage aurait dû être clôturé automatiquement mais aucune étape \"Fermé\" n'a été trouvée, l'opération demandée est impossible.\n" -"Pour régler ce problème, vous devez cocher \"Fermée\" sur au moins une étape." - -#. module: survey_deadline_autoclose -#: code:addons/survey_deadline_autoclose/models/survey_survey.py:22 -#: model:mail.message.subtype,description:survey_deadline_autoclose.mail_message_subtype_survey_expired -#, python-format -msgid "This survey has expired." -msgstr "Ce sondage est arrivé à échéance." - -#. module: survey_deadline_autoclose -#: code:addons/survey_deadline_autoclose/models/survey_survey.py:75 -#, python-format -msgid "This survey was automatically closed." -msgstr "Ce sondage a été clôturé automatiquement." - +#: model:ir.model.fields,help:survey_deadline_autoclose.field_survey_survey__deadline +msgid "This survey will be automatically closed after this date." +msgstr "Ce sondage sera automatiquement clos passé cette date" diff --git a/survey_deadline_autoclose/models/survey_survey.py b/survey_deadline_autoclose/models/survey_survey.py index 98022f4..42eacc8 100644 --- a/survey_deadline_autoclose/models/survey_survey.py +++ b/survey_deadline_autoclose/models/survey_survey.py @@ -1,86 +1,46 @@ +from datetime import timedelta as tdelta from odoo import models, fields, api, _ -from odoo.exceptions import UserError class SurveySurvey(models.Model): _inherit = "survey.survey" @api.model - def cron_close_deadline_survey(self): - deadline = self.search( + def cron_close_passed_deadline_survey(self): + to_close = self.search( [ - ("date_deadline", "!=", False), - ("date_deadline", "<", fields.Date.today()), + ("deadline", "!=", False), + ("deadline", "<", fields.Date.today()), ] ) - to_close = deadline.filtered("auto_close") if to_close: - to_close.action_close_survey() - for survey in deadline - to_close: - survey.message_post( - subtype="survey_deadline_autoclose.mail_message_subtype_survey_deadline", - body=_("This survey has expired."), - ) - - date_deadline = fields.Date( - string="Deadline", copy=False, track_visibility="onchange" + # 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.", ) - auto_close = fields.Boolean( - string="Auto close", - default=False, - help="If checked, the survey will be automatically closed when deadline is overpassed.", - track_visibility="onchange", + active = fields.Boolean( + tracking=True, ) - # ACTIONS - - @api.multi def action_send_survey(self): self.ensure_one() action = super(SurveySurvey, self).action_send_survey() action["context"].update( { - "default_date_deadline": self.date_deadline, + "default_deadline": self.deadline, } ) return action - @api.multi - def action_close_survey(self): - stage = self.env["survey.stage"].search([("closed", "=", True)], limit=1) - if not stage: - if self.env.context.get("cron", False): - for survey in self: - survey.message_post( - subtype="survey_deadline_autoclose.mail_message_subtype_survey_closed", - subject=_("Survey closing impossible"), - body=_( - 'Survey should have been automatically closed but no "closed" ' - "stage was found, the requested operation was impossible to proceed.\n" - 'To fix this situation, you have to check "Closed" at least on one survey stage.' - ), - ) - else: - raise UserError( - _( - 'No "closed" stage found, the requested operation is impossible.\n' - 'To fix this situation, you have to check "Closed" at least on one survey stage.' - ) - ) - else: - self.write({"stage_id": stage.id}) - for survey in self: - survey.message_post( - subtype="survey_deadline_autoclose.mail_message_subtype_survey_closed", - body=_("This survey was automatically closed."), - ) - - # ONCHANGES - - @api.onchange("date_deadline") - def onchange_date_deadline(self): + def _track_subtype(self, init_values): self.ensure_one() - if not self.date_deadline: - self.auto_close = False - elif not self.auto_close: - self.auto_close = True + 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) diff --git a/survey_deadline_autoclose/views/survey_survey.xml b/survey_deadline_autoclose/views/survey_survey.xml index 31ac0e5..c5c3803 100644 --- a/survey_deadline_autoclose/views/survey_survey.xml +++ b/survey_deadline_autoclose/views/survey_survey.xml @@ -1,80 +1,63 @@ - - survey_deadline_autoclose survey.survey form + + survey_deadline_autoclose form survey.survey - + 28 - -