[IMP] mass_mailing

Added delivered field, number of delivered emails
Improved kanban view of mass mailing campaign
Improved statistics of segments, now daily instead of monthly

bzr revid: tde@openerp.com-20130910104623-7ljg0q9pebbcqk7m
This commit is contained in:
Thibault Delavallée 2013-09-10 12:46:23 +02:00
parent f583127c03
commit 316ce91243
4 changed files with 57 additions and 22 deletions

View File

@ -41,6 +41,8 @@ class MassMailingCampaign(osv.Model):
'opened': len([mail for mail in campaign.mail_ids if mail.opened]),
'replied': len([mail for mail in campaign.mail_ids if mail.replied]),
'bounced': len([mail for mail in campaign.mail_ids if mail.bounced]),
# delivered: shouldn't be: all mails - (failed + bounced) ?
'delivered': len([mail for mail in campaign.mail_ids if mail.state == 'sent' and not mail.bounced]),
}
return results
@ -73,12 +75,18 @@ class MassMailingCampaign(osv.Model):
'mail.mail', 'mass_mailing_campaign_id',
'Sent Emails',
),
'color': fields.integer('Color Index'),
# stat fields
'sent': fields.function(
_get_statistics,
string='Sent Emails',
type='integer', multi='_get_statistics'
),
'delivered': fields.function(
_get_statistics,
string='Delivered',
type='integer', multi='_get_statistics',
),
'opened': fields.function(
_get_statistics,
string='Opened',
@ -120,16 +128,16 @@ class MassMailingSegment(osv.Model):
}
]
"""
month_begin = date.today().replace(day=1)
# month_begin = date.today().replace(day=1)
date_begin = date.today()
section_result = [{'value': 0,
'tooltip': (month_begin + relativedelta.relativedelta(months=-i)).strftime('%B'),
'tooltip': (date_begin + relativedelta.relativedelta(days=-i)).strftime('%d %B %Y'),
} for i in range(self._period_number - 1, -1, -1)]
group_obj = obj.read_group(cr, uid, domain, read_fields, groupby_field, context=context)
print group_obj
for group in group_obj:
group_begin_date = datetime.strptime(group['__domain'][0][2], tools.DEFAULT_SERVER_DATE_FORMAT)
month_delta = relativedelta.relativedelta(month_begin, group_begin_date)
section_result[self._period_number - (month_delta.months + 1)] = {'value': group.get(value_field, 0), 'tooltip': group_begin_date.strftime('%B')}
month_delta = relativedelta.relativedelta(date_begin, group_begin_date)
section_result[self._period_number - (month_delta.days + 1)] = {'value': group.get(value_field, 0), 'tooltip': group.get(groupby_field)}
return section_result
def _get_monthly_statistics(self, cr, uid, ids, field_name, arg, context=None):
@ -137,8 +145,20 @@ class MassMailingSegment(osv.Model):
"""
obj = self.pool.get('mail.mail')
res = dict.fromkeys(ids, False)
month_begin = date.today().replace(day=1)
groupby_begin = (month_begin + relativedelta.relativedelta(months=-4)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
date_begin = date.today()
context['datetime_format'] = {
'opened': {
'interval': 'day',
'groupby_format': 'yyyy-mm-dd',
'display_format': 'dd MMMM YYYY'
},
'replied': {
'interval': 'day',
'groupby_format': 'yyyy-mm-dd',
'display_format': 'dd MMMM YYYY'
},
}
groupby_begin = (date_begin + relativedelta.relativedelta(days=-4)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
for id in ids:
res[id] = dict()
domain = [('mass_mailing_segment_id', '=', id), ('opened', '>=', groupby_begin)]
@ -153,6 +173,7 @@ class MassMailingSegment(osv.Model):
for segment in self.browse(cr, uid, ids, context=context):
results[segment.id] = {
'sent': len(segment.mail_ids),
'delivered': len([mail for mail in segment.mail_ids if mail.state == 'sent' and not mail.bounced]),
'opened': len([mail for mail in segment.mail_ids if mail.opened]),
'replied': len([mail for mail in segment.mail_ids if mail.replied]),
'bounced': len([mail for mail in segment.mail_ids if mail.bounced]),
@ -181,6 +202,11 @@ class MassMailingSegment(osv.Model):
string='Sent Emails',
type='integer', multi='_get_statistics'
),
'delivered': fields.function(
_get_statistics,
string='Delivered',
type='integer', multi='_get_statistics',
),
'opened': fields.function(
_get_statistics,
string='Opened',

View File

@ -25,31 +25,31 @@
<record id="mass_mail_segment_1" model="mail.mass_mailing.segment">
<field name="name">First Newsletter</field>
<field name="template_id" eval="ref('mass_mail_template_1')"/>
<field name="date" eval="(DateTime.today() - relativedelta(month=2)).replace(day=1)"/>
<field name="date" eval="(DateTime.today() - relativedelta(day=3)"/>
<field name="mass_mailing_campaign_id" eval="ref('mass_mail_campaign_1')"/>
</record>
<record id="mass_mail_segment_2" model="mail.mass_mailing.segment">
<field name="name">Second Newsletter</field>
<field name="template_id" eval="ref('mass_mail_template_2')"/>
<field name="date" eval="(DateTime.today() - relativedelta(month=1)).replace(day=1)"/>
<field name="date" eval="(DateTime.today() - relativedelta(day=3)"/>
<field name="mass_mailing_campaign_id" eval="ref('mass_mail_campaign_1')"/>
</record>
<record id="mass_mail_email_1" model="mail.mail">
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=15)).strftime('%Y-%m-%d %H:%M')"/>
<field name="replied" eval="(DateTime.today() - relativedelta(days=10)).strftime('%Y-%m-%d %H:%M')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="replied" eval="(DateTime.today() - relativedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="state">sent</field>
</record>
<record id="mass_mail_email_2" model="mail.mail">
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
<field name="replied" eval="(DateTime.today() - relativedelta(days=0)).strftime('%Y-%m-%d %H:%M')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="replied" eval="(DateTime.today() - relativedelta(days=0)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="state">sent</field>
</record>
<record id="mass_mail_email_3" model="mail.mail">
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=0)).strftime('%Y-%m-%d %H:%M')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="state">sent</field>
</record>
<record id="mass_mail_email_4" model="mail.mail">
@ -58,18 +58,18 @@
</record>
<record id="mass_mail_email_5" model="mail.mail">
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
<field name="bounced" eval="(DateTime.today() - relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
<field name="bounced" eval="(DateTime.today() - relativedelta(days=3)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="state">sent</field>
</record>
<record id="mass_mail_email_2_1" model="mail.mail">
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_2')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=15)).strftime('%Y-%m-%d %H:%M')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=3)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="state">sent</field>
</record>
<record id="mass_mail_email_2_2" model="mail.mail">
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_2')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
<field name="opened" eval="(DateTime.today() - relativedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="state">sent</field>
</record>
<record id="mass_mail_email_2_3" model="mail.mail">

View File

@ -23,6 +23,7 @@
<group>
<field name="name"/>
<field name="sent"/>
<field name="delivered"/>
<field name="opened"/>
<field name="replied"/>
<field name="bounced"/>
@ -41,6 +42,7 @@
<kanban>
<field name="segment_kanban_ids"/>
<field name='sent'/>
<field name='color'/>
<templates>
<t t-name="mass_mailing.segment">
<div>
@ -66,16 +68,23 @@
</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"> -->
<div t-attf-class="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 oe_kanban_mass_mailing_campaign">
<div class="oe_dropdown_toggle oe_dropdown_kanban">
<span class="oe_e">i</span>
<ul class="oe_dropdown_menu">
<li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
</ul>
</div>
<div class="oe_kanban_content">
<h3>
<field name="name"/>
</h3>
<div>
<field name="opened" widget="gauge" style="width:120px; height: 80px;"
<field name="delivered" widget="gauge" style="width:160px; height: 120px;"
options="{'max_field': 'sent'}"/>
<field name="replied" widget="gauge" style="width:120px; height: 80px;"
<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'}"/>
</div>
<t t-foreach='record.segment_kanban_ids.value' t-as='segment'>

View File

@ -1,5 +1,5 @@
.openerp .oe_kanban_view .oe_kanban_mass_mailing.oe_kanban_mass_mailing_campaign {
width: 270px;
width: 540px;
}
.openerp .oe_kanban_view .oe_kanban_mass_mailing.oe_kanban_mass_mailing_segment {