[IMP] mass_mailing: campaign and mailing kanban view update

to match new specs, removed unnecessary CSS.

Also added a sent field on mail mail statistics, to be able to count the
number of really sent emails.

bzr revid: tde@openerp.com-20140317160919-7sx7ja28zaxid67t
This commit is contained in:
Thibault Delavallée 2014-03-17 17:09:19 +01:00
parent b778e5c7fa
commit 61f90f4581
5 changed files with 123 additions and 242 deletions

View File

@ -63,3 +63,8 @@ class MailMail(osv.Model):
if tracking_url:
body = tools.append_content_to_html(body, tracking_url, plaintext=False, container_tag='div')
return body
def _postprocess_sent_message(self, cr, uid, mail, context=None):
if mail.state == 'sent' and mail.statistics_ids:
self.pool['mail.mail.statistics'].write(cr, uid, [s.id for s in mail.statistics_ids], {'sent': fields.datetime.now()}, context=context)
return super(MailMail, self)._postprocess_sent_message(cr, uid, mail, context=context)

View File

@ -178,30 +178,17 @@ class MassMailingCampaign(osv.Model):
def _get_statistics(self, cr, uid, ids, name, arg, context=None):
""" Compute statistics of the mass mailing campaign """
Statistics = self.pool['mail.mail.statistics']
results = dict.fromkeys(ids, False)
for campaign in self.browse(cr, uid, ids, context=context):
results[campaign.id] = {
'sent': len(campaign.statistics_ids),
# delivered: shouldn't be: all mails - (failed + bounced) ?
'delivered': len([stat for stat in campaign.statistics_ids if not stat.bounced]), # stat.state == 'sent' and
'opened': len([stat for stat in campaign.statistics_ids if stat.opened]),
'replied': len([stat for stat in campaign.statistics_ids if stat.replied]),
'bounced': len([stat for stat in campaign.statistics_ids if stat.bounced]),
for cid in ids:
results[cid] = {
'total': Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid)], count=True, context=context),
'sent': Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid), ('sent', '!=', False)], count=True, context=context),
'opened': Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid), ('opened', '!=', False)], count=True, context=context),
'replied': Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid), ('replied', '!=', False)], count=True, context=context),
'bounced': Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid), ('bounced', '!=', False)], count=True, context=context),
}
return results
def _get_mass_mailing_kanban_ids(self, cr, uid, ids, name, arg, context=None):
""" Gather data about mass mailings to display them in kanban view as
nested kanban views is not possible currently. """
results = dict.fromkeys(ids, '')
for campaign in self.browse(cr, uid, ids, context=context):
mass_mailing_results = []
for mass_mailing in campaign.mass_mailing_ids[:self._kanban_mailing_nbr]:
mass_mailing_object = {}
for attr in ['name', 'sent', 'delivered', 'opened', 'replied', 'bounced']:
mass_mailing_object[attr] = getattr(mass_mailing, attr)
mass_mailing_results.append(mass_mailing_object)
results[campaign.id] = mass_mailing_results
results[cid]['delivered'] = results[cid]['sent'] - results[cid]['bounced']
return results
def _get_state_list(self, cr, uid, context=None):
@ -211,16 +198,12 @@ class MassMailingCampaign(osv.Model):
_state = lambda self, *args, **kwargs: self._get_state_list(*args, **kwargs)
_columns = {
'name': fields.char(
'Campaign Name', required=True,
),
'name': fields.char('Name', required=True),
'state': fields.selection(_state, string='Status', required=True),
'user_id': fields.many2one(
'res.users', 'Responsible',
required=True,
),
'state': fields.selection(
_state, string='Status', required=True,
),
'category_id': fields.many2one(
'mail.mass_mailing.category', 'Category',
help='Category'),
@ -228,42 +211,34 @@ class MassMailingCampaign(osv.Model):
'mail.mass_mailing', 'mass_mailing_campaign_id',
'Mass Mailings',
),
'mass_mailing_kanban_ids': fields.function(
_get_mass_mailing_kanban_ids,
type='text', string='Mass Mailings (kanban data)',
help='This field has for purpose to gather data about mass mailings '
'to display them in kanban view as nested kanban views is not '
'possible currently',
),
'statistics_ids': fields.one2many(
'mail.mail.statistics', 'mass_mailing_campaign_id',
'Sent Emails',
),
'color': fields.integer('Color Index'),
# stat fields
'total': fields.function(
_get_statistics, string='Scheduled',
type='integer', multi='_get_statistics'
),
'sent': fields.function(
_get_statistics,
string='Sent Emails',
_get_statistics, string='Sent Emails',
type='integer', multi='_get_statistics'
),
'delivered': fields.function(
_get_statistics,
string='Delivered',
_get_statistics, string='Delivered',
type='integer', multi='_get_statistics',
),
'opened': fields.function(
_get_statistics,
string='Opened',
_get_statistics, string='Opened',
type='integer', multi='_get_statistics',
),
'replied': fields.function(
_get_statistics,
string='Replied',
_get_statistics, string='Replied',
type='integer', multi='_get_statistics'
),
'bounced': fields.function(
_get_statistics,
string='Bounced',
_get_statistics, string='Bounced',
type='integer', multi='_get_statistics'
),
}
@ -306,21 +281,15 @@ class MassMailingCampaign(osv.Model):
# Actions
#------------------------------------------------------
def launch_mass_mailing_create_wizard(self, cr, uid, ids, context=None):
ctx = dict(context)
ctx.update({
'default_mass_mailing_campaign_id': ids[0],
})
def action_new_mailing(self, cr, uid, ids, context=None):
return {
'name': _('Create a Mass Mailing for the Campaign'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.mass_mailing.create',
'res_model': 'mail.mass_mailing',
'views': [(False, 'form')],
'view_id': False,
'target': 'new',
'context': ctx,
'context': dict(context, default_mass_mailing_campaign_id=ids[0]),
}
@ -383,15 +352,17 @@ class MassMailing(osv.Model):
def _get_statistics(self, cr, uid, ids, name, arg, context=None):
""" Compute statistics of the mass mailing campaign """
Statistics = self.pool['mail.mail.statistics']
results = dict.fromkeys(ids, False)
for mass_mailing in self.browse(cr, uid, ids, context=context):
results[mass_mailing.id] = {
'sent': len(mass_mailing.statistics_ids),
'delivered': len([stat for stat in mass_mailing.statistics_ids if not stat.bounced]), # mail.state == 'sent' and
'opened': len([stat for stat in mass_mailing.statistics_ids if stat.opened]),
'replied': len([stat for stat in mass_mailing.statistics_ids if stat.replied]),
'bounced': len([stat for stat in mass_mailing.statistics_ids if stat.bounced]),
for mid in ids:
results[mid] = {
'total': Statistics.search(cr, uid, [('mass_mailing_id', '=', mid)], count=True, context=context),
'sent': Statistics.search(cr, uid, [('mass_mailing_id', '=', mid), ('sent', '!=', False)], count=True, context=context),
'opened': Statistics.search(cr, uid, [('mass_mailing_id', '=', mid), ('opened', '!=', False)], count=True, context=context),
'replied': Statistics.search(cr, uid, [('mass_mailing_id', '=', mid), ('replied', '!=', False)], count=True, context=context),
'bounced': Statistics.search(cr, uid, [('mass_mailing_id', '=', mid), ('bounced', '!=', False)], count=True, context=context),
}
results[mid]['delivered'] = results[mid]['sent'] - results[mid]['bounced']
return results
def _get_mailing_type(self, cr, uid, context=None):
@ -447,41 +418,38 @@ class MassMailing(osv.Model):
'mail.mail.statistics', 'mass_mailing_id',
'Emails Statistics',
),
'total': fields.function(
_get_statistics, string='Scheduled',
type='integer', multi='_get_statistics'
),
'sent': fields.function(
_get_statistics,
string='Sent Emails',
_get_statistics, string='Sent',
type='integer', multi='_get_statistics'
),
'delivered': fields.function(
_get_statistics,
string='Delivered',
_get_statistics, string='Delivered',
type='integer', multi='_get_statistics',
),
'opened': fields.function(
_get_statistics,
string='Opened',
_get_statistics, string='Opened',
type='integer', multi='_get_statistics',
),
'replied': fields.function(
_get_statistics,
string='Replied',
_get_statistics, string='Replied',
type='integer', multi='_get_statistics'
),
'bounced': fields.function(
_get_statistics,
string='Bounce',
_get_statistics, string='Bounced',
type='integer', multi='_get_statistics'
),
# monthly ratio
'opened_dayly': fields.function(
_get_daily_statistics,
string='Opened',
_get_daily_statistics, string='Opened',
type='char', multi='_get_daily_statistics',
oldname='opened_monthly',
),
'replied_dayly': fields.function(
_get_daily_statistics,
string='Replied',
_get_daily_statistics, string='Replied',
type='char', multi='_get_daily_statistics',
oldname='replied_monthly',
),
@ -673,6 +641,9 @@ class MailMailStats(osv.Model):
store=True, readonly=True,
),
# Bounce and tracking
'sent': fields.datetime(
'Sent',
help='Date the related email was sent'),
'opened': fields.datetime(
'Opened',
help='Date when this email has been opened for the first time.'),
@ -688,38 +659,29 @@ class MailMailStats(osv.Model):
def set_opened(self, cr, uid, ids=None, mail_mail_ids=None, mail_message_ids=None, context=None):
""" Set as opened """
if not ids and mail_mail_ids:
ids = self.search(cr, uid, [('mail_mail_id', 'in', mail_mail_ids)], context=context)
ids = self.search(cr, uid, [('mail_mail_id', 'in', mail_mail_ids), ('opened', '=', False)], context=context)
elif not ids and mail_message_ids:
ids = self.search(cr, uid, [('message_id', 'in', mail_message_ids)], context=context)
ids = self.search(cr, uid, [('message_id', 'in', mail_message_ids), ('opened', '=', False)], context=context)
else:
ids = []
for stat in self.browse(cr, uid, ids, context=context):
if not stat.opened:
self.write(cr, uid, [stat.id], {'opened': fields.datetime.now()}, context=context)
return ids
ids = self.search(cr, uid, [('id', 'in', ids or []), ('opened', '=', False)], context=context)
return self.write(cr, uid, ids, {'opened': fields.datetime.now()}, context=context)
def set_replied(self, cr, uid, ids=None, mail_mail_ids=None, mail_message_ids=None, context=None):
""" Set as replied """
if not ids and mail_mail_ids:
ids = self.search(cr, uid, [('mail_mail_id', 'in', mail_mail_ids)], context=context)
ids = self.search(cr, uid, [('mail_mail_id', 'in', mail_mail_ids), ('replied', '=', False)], context=context)
elif not ids and mail_message_ids:
ids = self.search(cr, uid, [('message_id', 'in', mail_message_ids)], context=context)
ids = self.search(cr, uid, [('message_id', 'in', mail_message_ids), ('replied', '=', False)], context=context)
else:
ids = []
for stat in self.browse(cr, uid, ids, context=context):
if not stat.replied:
self.write(cr, uid, [stat.id], {'replied': fields.datetime.now()}, context=context)
return ids
ids = self.search(cr, uid, [('id', 'in', ids or []), ('replied', '=', False)], context=context)
return self.write(cr, uid, ids, {'replied': fields.datetime.now()}, context=context)
def set_bounced(self, cr, uid, ids=None, mail_mail_ids=None, mail_message_ids=None, context=None):
""" Set as bounced """
if not ids and mail_mail_ids:
ids = self.search(cr, uid, [('mail_mail_id', 'in', mail_mail_ids)], context=context)
ids = self.search(cr, uid, [('mail_mail_id', 'in', mail_mail_ids), ('bounced', '=', False)], context=context)
elif not ids and mail_message_ids:
ids = self.search(cr, uid, [('message_id', 'in', mail_message_ids)], context=context)
ids = self.search(cr, uid, [('message_id', 'in', mail_message_ids), ('bounced', '=', False)], context=context)
else:
ids = []
for stat in self.browse(cr, uid, ids, context=context):
if not stat.bounced:
self.write(cr, uid, [stat.id], {'bounced': fields.datetime.now()}, context=context)
return ids
ids = self.search(cr, uid, [('id', 'in', ids or []), ('bounced', '=', False)], context=context)
return self.write(cr, uid, ids, {'bounced': fields.datetime.now()}, context=context)

View File

@ -1,61 +1,17 @@
.openerp .oe_kanban_view .oe_kanban_mass_mailing.oe_kanban_mass_mailing_campaign {
.openerp .oe_kanban_view .oe_kanban_mass_mailing_campaign {
/* Customize to manage content */
width: 552px;
min-height: 278px !important;
width: 360px;
min-height: 254px !important;
/* End of customize */
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing.oe_kanban_mass_mailing_segment {
.openerp .oe_kanban_view .oe_kanban_mass_mailing_campaign .oe_kanban_header_right {
float: right;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing {
/* Customize to manage content */
width: 282px;
min-height: 246px !important;
width: 280px;
min-height: 150px !important;
/* End of customize */
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_mail_stats {
width: 122px; /* Manage space in between stats */
display: inline-block;
margin: 2px 5px 0px 5px;
text-align: center;
border: 1px solid rgba(0, 0, 0, 0.16);
-webkit-border-radius: 2px;
border-radius: 2px;
background-color: #FFFFFF;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_mail_result {
font-weight: bold;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_gauge {
width: 120px;
height: 120px;
display: inline-block;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_kanban_content div.oe_sparkline_container {
height: 60px;
width: 120px;
display: inline-block;
margin: 8px 5px 0px 5px;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_sparkline_bar_title {
text-align: center;
display: inline;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_sparkline_bar {
width: 100px;
height: 60px;
display: inline-block;
}
/*
* Campaign related CSS
*/
/*
* Segment related CSS
*/

View File

@ -3,7 +3,7 @@ openerp.mass_mailing = function(openerp) {
openerp.web_kanban.KanbanRecord.include({
on_card_clicked: function (event) {
if (this.view.dataset.model === 'mail.mass_mailing.campaign') {
this.$('.oe_mass_mailings a').first().click();
this.$('.oe_mailings').click();
} else {
this._super.apply(this, arguments);
}

View File

@ -253,47 +253,27 @@
<field name="arch" type="xml">
<kanban default_group_by='state'>
<field name='color'/>
<field name='total'/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_kanban_mass_mailing oe_kanban_mass_mailing_segment">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_kanban_mass_mailing">
<div class="oe_kanban_content">
<div>
<h3>
<field name="name"/>
</h3>
<p style="margin-left: 10px; margin-top: 8px;">
<span>Sent:</span><field name="date"/><br />
<span groups="mass_mailing.mass_mailing_campaign_id">Campaign:</span>
<field name="mass_mailing_campaign_id" groups="mass_mailing.mass_mailing_campaign_id"/>
</p>
<h3><field name="name"/></h3>
<h4 style="display: inline;"><field name="mass_mailing_campaign_id" groups="mass_mailing.group_mass_mailing_campaign"/></h4>
<t t-if="record.mass_mailing_campaign_id.raw_value"> - </t><field name="date"/>
</div>
<div>
<p class="oe_mail_stats">
<span class="oe_mail_result"><field name="sent"/></span><br />
Sent
</p>
<p class="oe_mail_stats">
<span class="oe_mail_result"><field name="delivered"/></span><br />
Delivered
</p>
<p class="oe_mail_stats">
<span class="oe_mail_result"><field name="opened"/></span><br />
Opened
</p>
<p class="oe_mail_stats">
<span class="oe_mail_result"><field name="replied"/></span><br />
Replied
</p>
<field name="total" widget="gauge" style="width:120px; height: 90px;"
options="{'max_field': 'total'}"/>
<field name="delivered" widget="gauge" style="width:120px; height: 90px;"
options="{'max_field': 'total'}"/>
</div>
<div>
<div class="oe_sparkline_container">
<h4 class="oe_sparkline_bar_title">Opened</h4><br />
<field name="opened_dayly" widget="sparkline_bar" options="{'height': '50px', 'barWidth': 10, 'barSpacing': 5}"/>
</div>
<div class="oe_sparkline_container">
<h4 class="oe_sparkline_bar_title">Replied</h4><br />
<field name="replied_dayly" widget="sparkline_bar" options="{'height': '50px', 'barWidth': 10, 'barSpacing': 5}"/>
</div>
<field name="opened" widget="gauge" style="width:120px; height: 90px;"
options="{'max_field': 'total'}"/>
<field name="replied" widget="gauge" style="width:120px; height: 90px;"
options="{'max_field': 'total'}"/>
</div>
</div>
<div class="oe_clear"></div>
@ -366,27 +346,20 @@
<field name="arch" type="xml">
<form string="Mass Mailing Campaign" version="7.0">
<header>
<button name="launch_mass_mailing_create_wizard" type="object"
class="oe_highlight" string="New Mailing"/>
<button name="action_new_mailing" type="object" class="oe_highlight" string="New Mailing"/>
<field name="state" widget="statusbar" clickable="True"/>
</header>
<sheet>
<group>
<field name="name"/>
<field name="user_id"/>
<field name="category_id"/>
<group>
<field name="name"/>
<field name="user_id"/>
<field name="category_id"/>
</group>
<group>
here be some graphs
</group>
</group>
<!-- <group>
<group>
<field name="sent"/>
<field name="opened"/>
<field name="bounced"/>
</group>
<group>
<field name="delivered"/>
<field name="replied"/>
</group>
</group> -->
<group>
<field name="mass_mailing_ids" readonly="1" string="Related Mailing(s)">
<tree>
@ -411,39 +384,13 @@
<field name="model">mail.mass_mailing.campaign</field>
<field name="arch" type="xml">
<kanban default_group_by='state'>
<field name="mass_mailing_kanban_ids"/>
<field name='sent'/>
<field name='total'/>
<field name='color'/>
<field name='user_id'/>
<field name='mass_mailing_ids'/>
<templates>
<t t-name="mass_mailing.mass_mailing">
<div class="oe_mass_mailings">
<div>
<a name="%(action_view_mass_mailings_from_campaign)d" type="action">
<h4><t t-raw="mass_mailing.name"/></h4>
</a>
</div>
<div>
<p class="oe_mail_stats">
<span class="oe_mail_result"><t t-raw="mass_mailing.sent"/></span><br />
Sent
</p>
<p class="oe_mail_stats">
<span class="oe_mail_result"><t t-raw="mass_mailing.delivered"/></span><br />
Delivered
</p>
<p class="oe_mail_stats">
<span class="oe_mail_result"><t t-raw="mass_mailing.opened"/></span><br />
Opened
</p>
<p class="oe_mail_stats">
<span class="oe_mail_result"><t t-raw="mass_mailing.replied"/></span><br />
Replied
</p>
</div>
</div>
</t>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_kanban_mass_mailing oe_kanban_mass_mailing_campaign">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_kanban_mass_mailing_campaign">
<div class="oe_dropdown_toggle oe_dropdown_kanban">
<span class="oe_e">i</span>
<ul class="oe_dropdown_menu">
@ -457,20 +404,31 @@
</ul>
</div>
<div class="oe_kanban_content">
<h3>
<field name="name"/>
</h3>
<div>
<field name="delivered" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'sent'}"/>
<field name="opened" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'sent'}"/>
<field name="replied" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'sent'}"/>
<img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)"
t-att-title="record.user_id.value" width="48" height="48o" class="oe_kanban_avatar oe_kanban_header_right"/>
<h3>
<field name="name"/>
</h3>
<span class="oe_tag"><field name="category_id"/></span>
<a name="%(action_view_mass_mailings_from_campaign)d" type="action"
class="oe_mailings">
<h4><t t-raw="record.mass_mailing_ids.raw_value.length"/> Mailings</h4>
</a>
</div>
<div class="oe_clear"></div>
<div>
<field name="total" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'total'}"/>
<field name="delivered" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'total'}"/>
</div>
<div>
<field name="opened" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'total'}"/>
<field name="replied" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'total'}"/>
</div>
<t t-foreach='record.mass_mailing_kanban_ids.value' t-as='mass_mailing'>
<t t-call="mass_mailing.mass_mailing"/>
</t>
</div>
<div class="oe_clear"></div>
</div>