RemiFr82
1 week ago
6 changed files with 101 additions and 224 deletions
-
15survey_deadline_autoclose/__manifest__.py
-
13survey_deadline_autoclose/data/ir_cron.xml
-
21survey_deadline_autoclose/data/mail_message_subtype.xml
-
107survey_deadline_autoclose/i18n/fr.po
-
84survey_deadline_autoclose/models/survey_survey.py
-
85survey_deadline_autoclose/views/survey_survey.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> |
|||
|
@ -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) |
@ -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> |
|||
|
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue