[ADD] mass_mailing_crm: add UTM statistics on mass mailing linked to lead/opportunities

Purpose: better showcase the integration between email marketing and crm
application thanks to UTM links.

Specifications

 * add 2 stat buttons to the mass mailing form;
 * XX Leads -> redirects to lead list view (should include both types: leads
   & opportunities), only visible if Leads are activated in CRM settings;
 * YY Opportunities -> redirects to opportunities list view (only
   opportunities);
 * those stats buttons are linked to UTM trackers used in the mass mailing
   itself: campaign, source and medium. Those can be configured notably using
   the website_link module;
 * display the stat buttons even if no data;
 * update demo data;

This commit is linked to task ID 1872198 and PR #26188.
This commit is contained in:
Thibault Delavallée
2018-08-09 13:30:28 +02:00
parent 28433c0a3c
commit f028ba56d1
6 changed files with 191 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+18
View File
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Mass mailing on lead / opportunities',
'category': 'Hidden',
'version': '1.0',
'summary': 'Add lead / opportunities UTM info on mass mailing',
'description': """UTM and mass mailing on lead / opportunities""",
'depends': ['crm', 'mass_mailing'],
'data': [
'views/mass_mailing_views.xml',
],
'demo': [
'data/mass_mailing_demo.xml',
],
'auto_install': True,
}
@@ -0,0 +1,78 @@
<?xml version="1.0"?>
<odoo>
<data noupdate="1">
<record id="mass_mail_lead_0" model="mail.mass_mailing">
<field name="name">Lead Newsletter</field>
<field name="state">in_queue</field>
<field name="schedule_date" eval="(DateTime.today() + relativedelta(days=5)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="mass_mailing_campaign_id" eval="ref('mass_mailing.mass_mail_campaign_1')"/>
<field name="campaign_id" ref="utm.utm_campaign_email_campaign_products"/>
<field name="source_id" ref="utm.utm_source_mailing"/>
<field name="medium_id" ref="utm.utm_medium_email"/>
<field name="mailing_model_id" ref="crm.model_crm_lead"/>
<field name="mailing_domain">[]</field>
<field name="reply_to_mode">email</field>
<field name="reply_to">${object.company_id.email}</field>
<field name="body_html" type="html">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
<tbody>
<!-- HEADER -->
<tr>
<td align="center" style="min-width: 590px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: white; padding: 0; border-collapse:separate;">
<tr><td valign="middle">
<span style="font-size: 10px;">Hello</span><br/>
<span style="font-size: 20px; font-weight: bold;">
${object.name}
</span>
</td><td valign="middle" align="right">
<img src="${'/logo.png?company=%s' % object.company_id.id}" style="padding: 0px; margin: 0px; height: 48px;" alt="${object.company_id.name}"/>
</td></tr>
<tr><td colspan="2" style="text-align:center;">
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin:4px 0px 32px 0px;"/>
</td></tr>
</table>
</td>
</tr>
<!-- CONTENT -->
<tr>
<td style="min-width: 590px;">
<p>Dear ${object.name}</p>
<p>Great stories have personality. Consider telling a great story that provides personality. Writing a story with personality for potential clients will assist with making a relationship connection. This shows up in small quirks like word choices or phrases. Write from your point of view, not from someone else's experience.</p>
<p>Great stories are for everyone even when only written for just one person. If you try to write with a wide general audience in mind, your story will ring false and be bland. No one will be interested. Write for one person. If it’s genuine for the one, it’s genuine for the rest.</p>
</td>
</tr>
<!-- FOOTER -->
<tr>
<td align="center" style="min-width: 590px; padding: 0 8px 0 8px; font-size:11px;">
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 4px 0px;"/>
<b>${object.company_id.name}</b><br/>
<div style="color: #999999;">
${object.company_id.phone}
% if object.company_id.email
|
<a href="${'mailto:%s' % object.company_id.email}" style="text-decoration:none; color: #999999;">
${object.company_id.email}
</a>
% endif
${object.company_id.website}
|
<a href="'%s' % object.company_id.website" style="text-decoration:none; color: #999999;">
${object.company_id.website}
</a>
% endif
</div>
</td>
</tr>
</tbody>
</table>
</td></tr>
<!-- POWERED BY -->
<tr><td align="center" style="min-width: 590px;">
Powered by <a target="_blank" href="https://www.odoo.com?utm_source=db&amp;utm_medium=email" style="color: #875A7B;">Odoo</a>
</td></tr>
</table></field>
</record>
</data>
</odoo>
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import mass_mailing
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class MassMailing(models.Model):
_name = 'mail.mass_mailing'
_inherit = 'mail.mass_mailing'
crm_lead_activated = fields.Boolean('Use Leads', compute='_compute_crm_lead_activated')
crm_lead_count = fields.Integer('Lead Count', compute='_compute_crm_lead_count')
crm_opportunities_count = fields.Integer('Opportunities Count', compute='_compute_crm_opportunities_count')
def _compute_crm_lead_activated(self):
for mass_mailing in self:
mass_mailing.crm_lead_activated = self.env.user.has_group('crm.group_use_lead')
@api.depends('crm_lead_activated')
def _compute_crm_lead_count(self):
for mass_mailing in self:
if mass_mailing.mailing_model_name != 'crm.lead' or not mass_mailing.crm_lead_activated:
mass_mailing.crm_lead_count = 0
else:
mass_mailing.crm_lead_count = self.env['crm.lead'].search_count(self._get_crm_utm_domain())
@api.depends('crm_lead_activated')
def _compute_crm_opportunities_count(self):
for mass_mailing in self:
if mass_mailing.mailing_model_name != 'crm.lead' or mass_mailing.crm_lead_activated:
mass_mailing.crm_opportunities_count = 0
else:
mass_mailing.crm_opportunities_count = self.env['crm.lead'].search_count(self._get_crm_utm_domain())
@api.multi
def action_redirect_to_leads(self):
action = self.env.ref('crm.crm_lead_all_leads').read()[0]
action['domain'] = self._get_crm_utm_domain()
action['context'] = {'default_type': 'lead'}
return action
@api.multi
def action_redirect_to_opportunities(self):
action = self.env.ref('crm.crm_lead_opportunities').read()[0]
action['view_mode'] = 'tree,kanban,graph,pivot,form,calendar'
action['domain'] = self._get_crm_utm_domain()
return action
def _get_crm_utm_domain(self):
res = []
if self.campaign_id:
res.append(('campaign_id', '=', self.campaign_id.id))
if self.source_id:
res.append(('source_id', '=', self.source_id.id))
if self.medium_id:
res.append(('medium_id', '=', self.medium_id.id))
if not res:
res.append(('1', '=', '0'))
return res
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="mail_mass_mailing_view_form" model="ir.ui.view">
<field name="name">mail.mass_mailing.view.form.inherit.crm</field>
<field name="model">mail.mass_mailing</field>
<field name="inherit_id" ref="mass_mailing.view_mail_mass_mailing_form"/>
<field name="arch" type="xml">
<xpath expr="//button[hasclass('o_mass_mailing_button')]" position="before">
<field name="crm_lead_activated" invisible="1"/>
<button name="action_redirect_to_leads"
type="object"
icon="fa-star"
class="oe_stat_button"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'crm.lead'), ('crm_lead_activated', '=', False)]}" >
<field name="crm_lead_count" string="Leads" widget="statinfo"/>
</button>
<button name="action_redirect_to_opportunities"
type="object"
icon="fa-star"
class="oe_stat_button"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'crm.lead'), ('crm_lead_activated', '=', True)]}" >
<field name="crm_opportunities_count" string="Opportunities" widget="statinfo"/>
</button>
</xpath>
</field>
</record>
</odoo>