Browse Source

[MIG] survey_deadline_autoclose

16.0
RemiFr82 1 week ago
parent
commit
74ae747290
  1. 15
      survey_deadline_autoclose/__manifest__.py
  2. 13
      survey_deadline_autoclose/data/ir_cron.xml
  3. 21
      survey_deadline_autoclose/data/mail_message_subtype.xml
  4. 107
      survey_deadline_autoclose/i18n/fr.po
  5. 84
      survey_deadline_autoclose/models/survey_survey.py
  6. 85
      survey_deadline_autoclose/views/survey_survey.xml

15
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",
}

13
survey_deadline_autoclose/data/ir_cron.xml

@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- <data> -->
<record model="ir.cron" id="cron_close_expired_surveys">
<field name="name">Close expired surveys</field>
<field name="model_id" ref="survey.model_survey_survey"/>
<field name="model_id" ref="survey.model_survey_survey" />
<field name="state">code</field>
<field name="code">model.with_context(cron=True).cron_close_deadline_survey()</field>
<field name="active" eval="True"/>
<field name="user_id" ref="base.user_root"/>
<field name="code">model.with_context(cron=True).cron_close_passed_deadline_survey()</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="nextcall" eval="(datetime.today() + relativedelta(days=1)).strftime('%Y-%m-%d 00:08:00')"/>
<field name="nextcall" eval="(datetime.today() + relativedelta(days=1)).strftime('%Y-%m-%d 00:00:00')" />
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="doall" eval="False" />
</record>
</data>

21
survey_deadline_autoclose/data/mail_message_subtype.xml

@ -2,22 +2,13 @@
<odoo>
<data noupdate="1">
<record id="mail_message_subtype_survey_expired" model="mail.message.subtype">
<field name="name">Expired survey</field>
<record id="mail_message_subtype_survey_closing" model="mail.message.subtype">
<field name="name">Closing</field>
<field name="res_model">survey.survey</field>
<field name="default" eval="True"/>
<field name="hidden" eval="False"/>
<field name='internal' eval="True"/>
<field name="description">This survey has expired.</field>
</record>
<record id="mail_message_subtype_survey_closed" model="mail.message.subtype">
<field name="name">Closed survey</field>
<field name="res_model">survey.survey</field>
<field name="default" eval="True"/>
<field name="hidden" eval="False"/>
<field name='internal' eval="True"/>
<field name="description">This survey is closed.</field>
<field name="default" eval="True" />
<field name="hidden" eval="False" />
<field name='internal' eval="True" />
<field name="description">Survey closing</field>
</record>
</data>

107
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 ""
"<span class=\"fw-bold\">Deadline</span>\n"
" <br/>"
msgstr ""
"<span class=\"fw-bold\">Échéance</span>\n"
" <br/>"
#. 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"

84
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)

85
survey_deadline_autoclose/views/survey_survey.xml

@ -1,80 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="survey_survey_form" model="ir.ui.view">
<field name="name">survey_deadline_autoclose survey.survey form</field>
<record id="survey_survey_view_form" model="ir.ui.view">
<field name="name">survey_deadline_autoclose form</field>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_form"/>
<field name="inherit_id" ref="survey.survey_survey_view_form" />
<field name="priority">28</field>
<field name="arch" type="xml">
<field name="stage_id" position="before">
<button name="action_close_survey" string="Close survey" type="object" attrs="{'invisible': [('is_closed', '=', True)]}"/>
<field name="scoring_type" position="before">
<field name="deadline" />
</field>
<xpath expr="//field[@name='users_can_go_back']/../.." position="inside">
<group name="options">
</group>
</xpath>
<group name="options" position="inside">
<xpath expr="//field[@name='users_can_go_back']/.." position="move"/>
</group>
<group name="options" position="inside">
<group name="deadline" class="o_label_nowrap">
<field name="date_deadline" class="oe_inline"/>
<field name="auto_close" attrs="{'invisible': [('date_deadline','=',False)]}"/>
</group>
</group>
</field>
</record>
<record id="survey_survey_tree" model="ir.ui.view">
<field name="name">survey_deadline_autoclose survey.survey tree</field>
<record id="survey_survey_view_tree" model="ir.ui.view">
<field name="name">survey_deadline_autoclose tree</field>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_tree"/>
<field name="inherit_id" ref="survey.survey_survey_view_tree" />
<field name="priority">28</field>
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="decoration-muted">is_closed</attribute>
</tree>
<tree position="inside">
<field name="is_closed" invisible="1"/>
</tree>
<field name="stage_id" position="after">
<field name="date_deadline"/>
<field name="auto_close"/>
<field name="user_id" position="after">
<field name="deadline" />
</field>
</field>
</record>
<record id="survey_survey_kanban" model="ir.ui.view">
<field name="name">survey_deadline_autoclose survey.survey kanban</field>
<record id="survey_survey_view_kanban" model="ir.ui.view">
<field name="name">survey_deadline_autoclose kanban</field>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_kanban"/>
<field name="inherit_id" ref="survey.survey_survey_view_kanban" />
<field name="priority">28</field>
<field name="arch" type="xml">
<field name="title" position="after">
<field name="date_deadline"/>
<field name="auto_close"/>
</field>
<li id="survey_test" position="before">
<li t-if="record.date_deadline.raw_value" id="deadline" class="text-muted" t-att-title="record.auto_close.raw_value and 'Auto close on expiration' or 'Manual close'">
<t t-if="record.auto_close.raw_value">Expiration : <strong class="text-danger"><field name="date_deadline"/></strong></t>
<t t-else="">Expiration : <strong><field name="date_deadline"/></strong></t>
</li>
</li>
<xpath expr="//div[hasclass('o_survey_kanban_card_ungrouped', 'row', 'mx-0')]/div[1]" position="after">
<div t-if="!selection_mode" class="col-lg-1 col-sm-4 col-6 py-0 my-2">
<span class="fw-bold">Deadline</span>
<br />
<span class="text-muted">
<t t-if="record.deadline.raw_value">
<field name="deadline" widget="date" />
</t>
<t t-else="">
<i>Undefined</i>
</t>
</span>
</div>
</xpath>
</field>
</record>
<record id="survey_survey_search" model="ir.ui.view">
<field name="name">survey_deadline_autoclose survey.survey search</field>
<record id="survey_survey_view_search" model="ir.ui.view">
<field name="name">survey_deadline_autoclose search</field>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_survey_view_search"/>
<field name="inherit_id" ref="survey.survey_survey_view_search" />
<field name="priority">28</field>
<field name="arch" type="xml">
<search position="inside">
<group expand="0" string="Group By">
<filter string="Expiration month" name="group_date_deadline_month" context="{'group_by':'date_deadline:month'}"/>
</group>
</search>
<xpath expr="//filter[@name='group_by_responsible']" posititon="after">
<filter string="Deadline" name="group_by_deadline"
context="{'group_by':'deadline'}" />
</xpath>
</field>
</record>

Loading…
Cancel
Save