[IMP] event: improve event mail state display
Purpose ======= Show an icon representing the state of the event mail and number of contacted registrations instead of the simple checkbox "sent". Specifications ============== Instead of the checkbox "sent", an event mail can have 3 values 1. Sent, if all the mails has been sent; 2. Scheduled, if scheduled but no attendee have been contacted; 3. Running, if not all attendees have been contacted; Note that communication targeting "after registration" are always considered as being "running" as any new registration triggers a new communication. A new widget is added that displays an icon depending on the state. A new field holding contact count is added. When scheduler send emails it is updated to keep a count of sent communications. LINKS Task ID-2414658 COM PR odoo/odoo#63093 UPG PR odoo/upgrade#2014
This commit is contained in:
committed by
Thibault Delavallée
parent
e47725abd8
commit
69df7d3d8a
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': 'Events Organization',
|
||||
'version': '1.4',
|
||||
'version': '1.5',
|
||||
'website': 'https://www.odoo.com/page/events',
|
||||
'category': 'Marketing/Events',
|
||||
'summary': 'Trainings, Conferences, Meetings, Exhibitions, Registrations',
|
||||
@@ -44,4 +44,7 @@ Key Features
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'qweb': [
|
||||
'static/src/xml/field_icon_selection.xml',
|
||||
],
|
||||
}
|
||||
|
||||
@@ -86,6 +86,10 @@ class EventMailScheduler(models.Model):
|
||||
mail_registration_ids = fields.One2many('event.mail.registration', 'scheduler_id')
|
||||
mail_sent = fields.Boolean('Mail Sent on Event', copy=False)
|
||||
done = fields.Boolean('Sent', compute='_compute_done', store=True, copy=False)
|
||||
mail_state = fields.Selection(
|
||||
[('running', 'Running'), ('scheduled', 'Scheduled'), ('sent', 'Sent')],
|
||||
string='Global communication Status', compute='_compute_mail_state')
|
||||
mail_count_done = fields.Integer('# Sent', copy=False, readonly=True)
|
||||
|
||||
@api.depends('mail_sent', 'interval_type', 'event_id.registration_ids', 'mail_registration_ids.mail_sent')
|
||||
def _compute_done(self):
|
||||
@@ -107,6 +111,20 @@ class EventMailScheduler(models.Model):
|
||||
|
||||
scheduler.scheduled_date = date + _INTERVALS[scheduler.interval_unit](sign * scheduler.interval_nbr) if date else False
|
||||
|
||||
@api.depends('interval_type', 'scheduled_date', 'event_mail_sent')
|
||||
def _compute_mail_state(self):
|
||||
for scheduler in self:
|
||||
# registrations based
|
||||
if scheduler.interval_type == 'after_sub':
|
||||
scheduler.mail_state = 'running'
|
||||
# global event based
|
||||
elif scheduler.event_mail_sent:
|
||||
scheduler.mail_state = 'sent'
|
||||
elif scheduler.scheduled_date:
|
||||
scheduler.mail_state = 'scheduled'
|
||||
else:
|
||||
scheduler.mail_state = 'running'
|
||||
|
||||
def execute(self):
|
||||
for mail in self:
|
||||
now = fields.Datetime.now()
|
||||
@@ -120,12 +138,15 @@ class EventMailScheduler(models.Model):
|
||||
mail.write({'mail_registration_ids': lines})
|
||||
# execute scheduler on registrations
|
||||
mail.mail_registration_ids.execute()
|
||||
mail.mail_count_done = len(mail.mail_registration_ids.filtered(lambda reg: reg.mail_sent))
|
||||
else:
|
||||
# Do not send emails if the mailing was scheduled before the event but the event is over
|
||||
if not mail.mail_sent and mail.scheduled_date <= now and mail.notification_type == 'mail' and \
|
||||
(mail.interval_type != 'before_event' or mail.event_id.date_end > now):
|
||||
mail.event_id.mail_attendees(mail.template_id.id)
|
||||
mail.write({'mail_sent': True})
|
||||
mail.mail_count_done = len(mail.event_id.registration_ids.filtered(lambda reg: reg.state != 'cancel'))
|
||||
|
||||
return True
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
odoo.define('event.field_icon_selection', function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var registry = require('web.field_registry');
|
||||
var AbstractField = require('web.AbstractField');
|
||||
var QWeb = core.qweb;
|
||||
|
||||
var IconSelection = AbstractField.extend({
|
||||
supportedFieldTypes: ['char', 'text', 'selection'],
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_render: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.icon = this.nodeOptions[this.value];
|
||||
this.title = this.value.charAt(0).toUpperCase() + this.value.slice(1);
|
||||
this.$el.empty().append(QWeb.render('event.IconSelection', {'widget': this}));
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
registry.add('icon_selection', IconSelection);
|
||||
|
||||
return IconSelection;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="event.IconSelection">
|
||||
<i t-att-class="widget.icon" t-att-title="widget.title"/>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -4,6 +4,7 @@
|
||||
<template id="assets_backend" name="event assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<link rel="stylesheet" type="text/scss" href="/event/static/src/scss/event.scss"/>
|
||||
<script type="text/javascript" src="/event/static/src/js/field_icon_selection.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -266,7 +266,10 @@
|
||||
<field name="interval_nbr" attrs="{'readonly':[('interval_unit','=','now')]}"/>
|
||||
<field name="interval_unit"/>
|
||||
<field name="interval_type"/>
|
||||
<field name="done"/>
|
||||
<field name="scheduled_date" groups="base.group_no_one" string="Schedule date"/>
|
||||
<field name="mail_count_done"/>
|
||||
<field name="mail_state" widget="icon_selection" string=" "
|
||||
options="{'sent': 'fa fa-check', 'scheduled': 'fa fa-hourglass-half', 'running': 'fa fa-cogs'}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
@@ -750,7 +753,7 @@
|
||||
<field name="event_id"/>
|
||||
<field name="notification_type" invisible="1"/>
|
||||
<field name="template_id" attrs="{'required': [('notification_type', '=', 'mail')]}"/>
|
||||
<field name="mail_sent"/>
|
||||
<field name="mail_state"/>
|
||||
</group>
|
||||
<group>
|
||||
<label for="interval_nbr"/>
|
||||
@@ -787,8 +790,9 @@
|
||||
<field name="notification_type" invisible="1"/>
|
||||
<field name="template_id" attrs="{'required': [('notification_type', '=', 'mail')]}"/>
|
||||
<field name="scheduled_date"/>
|
||||
<field name="mail_sent" string="Sent"/>
|
||||
<field name="done"/>
|
||||
<field name="mail_count_done"/>
|
||||
<field name="mail_state" widget="icon_selection" string=" "
|
||||
options="{'sent': 'fa fa-check', 'scheduled': 'fa fa-hourglass-half', 'running': 'fa fa-cogs'}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -45,6 +45,9 @@ class EventMailScheduler(models.Model):
|
||||
mass_keep_log=True
|
||||
)
|
||||
mail.write({'mail_sent': True})
|
||||
|
||||
mail.mail_count_done = len(mail.event_id.registration_ids.filtered(lambda reg: reg.state != 'cancel'))
|
||||
|
||||
return super(EventMailScheduler, self).execute()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user