RemiFr82
2 weeks ago
6 changed files with 101 additions and 224 deletions
-
15survey_deadline_autoclose/__manifest__.py
-
5survey_deadline_autoclose/data/ir_cron.xml
-
15survey_deadline_autoclose/data/mail_message_subtype.xml
-
105survey_deadline_autoclose/i18n/fr.po
-
82survey_deadline_autoclose/models/survey_survey.py
-
83survey_deadline_autoclose/views/survey_survey.xml
@ -1,86 +1,46 @@ |
|||||
|
from datetime import timedelta as tdelta |
||||
from odoo import models, fields, api, _ |
from odoo import models, fields, api, _ |
||||
from odoo.exceptions import UserError |
|
||||
|
|
||||
|
|
||||
class SurveySurvey(models.Model): |
class SurveySurvey(models.Model): |
||||
_inherit = "survey.survey" |
_inherit = "survey.survey" |
||||
|
|
||||
@api.model |
@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: |
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."), |
|
||||
) |
|
||||
|
# to_close.action_close_survey() |
||||
|
to_close.action_archive() |
||||
|
|
||||
date_deadline = fields.Date( |
|
||||
string="Deadline", copy=False, track_visibility="onchange" |
|
||||
|
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): |
def action_send_survey(self): |
||||
self.ensure_one() |
self.ensure_one() |
||||
action = super(SurveySurvey, self).action_send_survey() |
action = super(SurveySurvey, self).action_send_survey() |
||||
action["context"].update( |
action["context"].update( |
||||
{ |
{ |
||||
"default_date_deadline": self.date_deadline, |
|
||||
|
"default_deadline": self.deadline, |
||||
} |
} |
||||
) |
) |
||||
return action |
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() |
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) |
@ -1,80 +1,63 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<odoo> |
<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="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="priority">28</field> |
||||
<field name="arch" type="xml"> |
<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> |
</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> |
</field> |
||||
</record> |
</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="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="priority">28</field> |
||||
<field name="arch" type="xml"> |
<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> |
||||
</field> |
</field> |
||||
</record> |
</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="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="priority">28</field> |
||||
<field name="arch" type="xml"> |
<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> |
</field> |
||||
</record> |
</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="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="priority">28</field> |
||||
<field name="arch" type="xml"> |
<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> |
</field> |
||||
</record> |
</record> |
||||
|
|
||||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue