[ADD] mass_mailing_sale: add UTM statistics on mass mailing linked to sale orders
Purpose: better showcase the integration between email marketing and sale application thanks to UTM links. Specifications * add 2 stat buttons to the mass mailing form; * XX Quotations -> redirects to quotation list view; * YY Invoiced -> redirects to invoice list view. Use the account invoice report to generate the invoiced amount; * 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:
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Mass mailing on sale orders',
|
||||
'category': 'Hidden',
|
||||
'version': '1.0',
|
||||
'summary': 'Add sale order UTM info on mass mailing',
|
||||
'description': """UTM and mass mailing on sale orders""",
|
||||
'depends': ['sale', 'mass_mailing', 'website_sale_link_tracker'],
|
||||
'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="0">
|
||||
<record id="mass_mail_sale_order_0" model="mail.mass_mailing">
|
||||
<field name="name">Sale 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="website_sale_link_tracker.utm_source_sale_order_0"/>
|
||||
<field name="medium_id" ref="utm.utm_medium_email"/>
|
||||
<field name="mailing_model_id" ref="sale.model_sale_order"/>
|
||||
<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&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,61 @@
|
||||
# -*- 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'
|
||||
|
||||
sale_quotation_count = fields.Integer('Quotation Count', compute='_compute_sale_quotation_count')
|
||||
sale_invoiced_amount = fields.Integer('Invoiced Amount', compute='_compute_sale_invoiced_amount')
|
||||
|
||||
@api.depends('mailing_domain')
|
||||
def _compute_sale_quotation_count(self):
|
||||
for mass_mailing in self:
|
||||
if mass_mailing.mailing_model_name != 'sale.order':
|
||||
mass_mailing.sale_quotation_count = 0
|
||||
else:
|
||||
mass_mailing.sale_quotation_count = self.env['sale.order'].search_count(self._get_sale_utm_domain())
|
||||
|
||||
@api.depends('mailing_domain')
|
||||
def _compute_sale_invoiced_amount(self):
|
||||
for mass_mailing in self:
|
||||
if mass_mailing.mailing_model_name != 'sale.order':
|
||||
mass_mailing.sale_invoiced_amount = 0
|
||||
else:
|
||||
invoices = self.env['sale.order'].search(self._get_sale_utm_domain()).mapped('invoice_ids')
|
||||
res = self.env['account.invoice.report'].search_read([('invoice_id', 'in', invoices.ids)], ['user_currency_price_total'])
|
||||
mass_mailing.sale_invoiced_amount = sum(r['user_currency_price_total'] for r in res)
|
||||
|
||||
@api.multi
|
||||
def action_redirect_to_quotations(self):
|
||||
action = self.env.ref('sale.action_quotations_with_onboarding').read()[0]
|
||||
action['domain'] = self._get_sale_utm_domain()
|
||||
action['context'] = {'default_type': 'lead'}
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def action_redirect_to_invoiced(self):
|
||||
action = self.env.ref('account.action_invoice_refund_out_tree').read()[0]
|
||||
invoices = self.env['sale.order'].search(self._get_sale_utm_domain()).mapped('invoice_ids')
|
||||
action['domain'] = [
|
||||
('id', 'in', invoices.ids),
|
||||
('type', 'in', ['out_invoice', 'out_refund']),
|
||||
('state', 'not in', ['draft', 'cancel'])
|
||||
]
|
||||
return action
|
||||
|
||||
def _get_sale_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,26 @@
|
||||
<?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.sale</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">
|
||||
<button name="action_redirect_to_quotations"
|
||||
type="object"
|
||||
icon="fa-usd"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': ['|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'sale.order')]}" >
|
||||
<field name="sale_quotation_count" string="Quotations" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="action_redirect_to_invoiced"
|
||||
type="object"
|
||||
icon="fa-money"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': ['|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'sale.order')]}" >
|
||||
<field name="sale_invoiced_amount" string="Invoiced" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user