Browse Source

[ADD] survey_deadline_autoclose module

12.0
Rémi FRANÇOIS 5 years ago
parent
commit
b6e7d096cd
  1. 1
      survey_deadline_autoclose/__init__.py
  2. 34
      survey_deadline_autoclose/__manifest__.py
  3. 21
      survey_deadline_autoclose/data/ir_cron.xml
  4. 22
      survey_deadline_autoclose/data/mail_message_subtype.xml
  5. 1
      survey_deadline_autoclose/models/__init__.py
  6. 53
      survey_deadline_autoclose/models/survey_survey.py
  7. 67
      survey_deadline_autoclose/views/survey_survey.xml

1
survey_deadline_autoclose/__init__.py

@ -0,0 +1 @@
from . import models

34
survey_deadline_autoclose/__manifest__.py

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Survey deadline auto-close',
'version': '0.1.0',
'summary': """
The module adds a deadline date on surveys and a checkbox to automatically close them with a planned action.
""",
'description': """ """,
'author': 'Sudokeys',
'website': 'http://www.sudokeys.com',
'license': 'AGPL-3',
'category': 'Marketing',
'depends': [
'survey',
],
'data': [
'data/ir_cron.xml',
'data/mail_message_subtype.xml',
'views/survey_survey.xml',
],
'demo': [],
'auto_install': False,
'external_dependencies': [],
'application': False,
'css': [],
'images': [],
'js': [],
'installable': True,
'maintainer': 'Sudokeys',
'pre_init_hook': '',
'post_init_hook': '',
'uninstall_hook': '',
}

21
survey_deadline_autoclose/data/ir_cron.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- <data> -->
<record model="ir.cron" id="set_customer_inactive">
<field name="name">Clôture des sondages arrivés à échéance</field>
<field name="model_id" ref="survey.model_survey_survey"/>
<field name="state">code</field>
<field name="code">model.action_close_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:10:00')"/>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
</record>
</data>
</odoo>

22
survey_deadline_autoclose/data/mail_message_subtype.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="mail_message_subtype_survey_deadline" model="mail.message.subtype">
<field name="name">Sondage Échu</field>
<field name="res_model">survey.survey</field>
<field name="default" eval="True"/>
<field name="hidden" eval="False"/>
<field name="description">Ce sondage est arrivé à échéance.</field>
</record>
<record id="mail_message_subtype_survey_closed" model="mail.message.subtype">
<field name="name">Sondage Clos</field>
<field name="res_model">survey.survey</field>
<field name="default" eval="True"/>
<field name="hidden" eval="False"/>
<field name="description">Ce sondage a été clôturé.</field>
</record>
</data>
</odoo>

1
survey_deadline_autoclose/models/__init__.py

@ -0,0 +1 @@
from . import survey_survey

53
survey_deadline_autoclose/models/survey_survey.py

@ -0,0 +1,53 @@
from odoo import models, fields, api
from odoo.exceptions import UserError
class SurveySurvey(models.Model):
_inherit = 'survey.survey'
@api.model
def close_deadline_survey(self):
deadline = self.search([
('date_deadline', '!=', False),
('date_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')
date_deadline = fields.Date(string="Date d'échéance", help="Passé cette date, il ne sera plus possible de répondre au sondage.", copy=False)
auto_close = fields.Boolean(string="Clôture automatique à l'échéance", default=False)
# 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,
})
return action
@api.multi
def action_close_survey(self):
stage = self.env['survey.stage'].search([('closed', '=', True)], limit=1)
if not stage:
raise UserError("Aucun statut qualifié de \"fermé\" n'a été trouvé, l'opération demandée est impossible.")
self.write({
'stage_id': stage.id
})
for survey in self:
survey.message_post(subtype='survey_deadline_autoclose.mail_message_subtype_survey_closed')
# ONCHANGES
@api.onchange('date_deadline')
def onchange_is_template(self):
self.ensure_one()
if not self.date_deadline:
self.auto_close = False
elif not self.auto_close:
self.auto_close = True

67
survey_deadline_autoclose/views/survey_survey.xml

@ -0,0 +1,67 @@
<?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>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_form"/>
<field name="priority">25</field>
<field name="arch" type="xml">
<field name="stage_id" position="before">
<button name="action_close_survey" string="Clore le sondage" type="object" attrs="{'invisible': [('is_closed', '=', True)]}"/>
</field>
<xpath expr="//group[hasclass('o_label_nowrap')]/.." position="inside">
<group name="options">
</group>
</xpath>
<group name="options" position="inside">
<xpath expr="//group[hasclass('o_label_nowrap')]" 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>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_tree"/>
<field name="priority">25</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>
</field>
</record>
<record id="survey_survey_kanban" model="ir.ui.view">
<field name="name">survey_deadline_autoclose survey.survey kanban</field>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_kanban"/>
<field name="priority">20</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." id="deadline" class="text-muted" t-att-title="record.auto_close.raw_value and 'Clôture automatique à l'échéance or 'Clôture manuelle'">
<t t-if="record.auto_close.raw_value">Échéance : <strong class="text-danger"><field name="date_deadline"/></strong></t>
<t t-else="">Échéance : <strong><field name="date_deadline"/></strong></t>
</li>
</li>
</field>
</record>
</odoo>
Loading…
Cancel
Save