[IMP] utm, mass_mailing: clean utm.campaign model, form view and stat buttons
This commit cleans up the utm.campaign form view:
* Don't display mailing related things if no mailings on the campaign or
if the campaigns were not activated in mass_mailing settings;
* Stat button for the mass mailings was wrong, it was displaying the number
of mails instead of the number of mailings;
* Remove unused global click ratio field all other fields/methods related
to its computation;
* Remove ab testing cta on campaign form;
* Add groups on mailing related fields to avoid access errors;
LINKS
Task ID 2074813 (FP request UTM refactor)
PR: #37185
This commit is contained in:
committed by
Thibault Delavallée
parent
ad98c63400
commit
af601da9be
@@ -8,9 +8,6 @@ class UtmCampaign(models.Model):
|
||||
_inherit = ['utm.campaign']
|
||||
_description = 'UTM Campaign'
|
||||
|
||||
items_total = fields.Integer(string="Number of items that are part of the campaign", compute="_compute_items_total")
|
||||
clicked_total = fields.Integer(string="Number of items that are part of the campaign who generated a click", compute="_compute_items_total")
|
||||
clicks_ratio = fields.Integer(string="Global Clicks Ratio for the campaign", compute="_compute_clicks_ratio")
|
||||
click_count = fields.Integer(string="Number of clicks generated by the campaign", compute="_compute_clicks_count")
|
||||
|
||||
def _compute_clicks_count(self):
|
||||
@@ -22,13 +19,3 @@ class UtmCampaign(models.Model):
|
||||
|
||||
for campaign in self:
|
||||
campaign.click_count = mapped_data.get(campaign.id, 0)
|
||||
|
||||
def _compute_items_total(self):
|
||||
"""Empty method that will be implemented by inheriting classes"""
|
||||
self.clicked_total = 0
|
||||
self.items_total = 0
|
||||
|
||||
@api.depends('items_total', 'clicked_total')
|
||||
def _compute_clicks_ratio(self):
|
||||
for campaign in self:
|
||||
campaign.clicks_ratio = campaign.clicked_total / campaign.items_total * 100 if campaign.items_total > 0 else 0
|
||||
|
||||
@@ -7,10 +7,12 @@ from odoo import api, fields, models
|
||||
class UtmCampaign(models.Model):
|
||||
_inherit = 'utm.campaign'
|
||||
|
||||
mailing_ids = fields.One2many(
|
||||
mailing_mail_ids = fields.One2many(
|
||||
'mailing.mailing', 'campaign_id',
|
||||
domain=[('mailing_type', '=', 'mail')],
|
||||
string='Mass Mailings')
|
||||
mailing_clicks_ratio = fields.Integer(default=0, compute="_compute_mailing_clicks_ratio", string="Number of clicks")
|
||||
mailing_mail_count = fields.Integer('Number of Mass Mailing', compute="_compute_mailing_mail_count")
|
||||
mailing_clicks_ratio = fields.Integer(compute="_compute_mailing_clicks_ratio", string="Number of clicks")
|
||||
mailing_items = fields.Integer(compute="_compute_mailing_items", string='Mailings')
|
||||
mailing_clicked = fields.Integer(compute="_compute_mailing_items", string='Mailings Clicked')
|
||||
# stat fields
|
||||
@@ -28,26 +30,21 @@ class UtmCampaign(models.Model):
|
||||
replied_ratio = fields.Integer(compute="_compute_statistics", string='Replied Ratio')
|
||||
bounced_ratio = fields.Integer(compute="_compute_statistics", string='Bounced Ratio')
|
||||
|
||||
@api.depends('mailing_items', 'mailing_clicked')
|
||||
def _compute_items_total(self):
|
||||
@api.depends('mailing_mail_ids')
|
||||
def _compute_mailing_mail_count(self):
|
||||
for campaign in self:
|
||||
campaign.items_total += campaign.mailing_items
|
||||
campaign.clicked_total += campaign.mailing_clicked
|
||||
campaign.mailing_mail_count = len(campaign.mailing_mail_ids)
|
||||
|
||||
def _compute_mailing_items(self):
|
||||
super(UtmCampaign, self)._compute_clicks_ratio()
|
||||
mapped_data = {}
|
||||
|
||||
if self.ids:
|
||||
query = """SELECT trace.campaign_id AS campaign_id, COUNT(DISTINCT(trace.id)) AS items_total, COUNT(DISTINCT(click.mailing_trace_id)) AS clicked_total
|
||||
FROM mailing_trace AS trace
|
||||
LEFT OUTER JOIN link_tracker_click as click ON click.mailing_trace_id = trace.id
|
||||
WHERE trace.campaign_id IN %s
|
||||
GROUP BY trace.campaign_id """
|
||||
params = [tuple(self.ids)]
|
||||
self.env.cr.execute(query, params)
|
||||
clicked_data = self.env.cr.dictfetchall()
|
||||
mapped_data = {datum['campaign_id']: {'clicked_total': datum['clicked_total'], 'items_total': datum['items_total']} for datum in clicked_data}
|
||||
query = """SELECT trace.campaign_id AS campaign_id, COUNT(DISTINCT(trace.id)) AS items_total, COUNT(DISTINCT(click.mailing_trace_id)) AS clicked_total
|
||||
FROM mailing_trace AS trace
|
||||
LEFT OUTER JOIN link_tracker_click as click ON click.mailing_trace_id = trace.id
|
||||
WHERE trace.campaign_id IN %s
|
||||
GROUP BY trace.campaign_id """
|
||||
params = [tuple(self.ids)]
|
||||
self.env.cr.execute(query, params)
|
||||
clicked_data = self.env.cr.dictfetchall()
|
||||
mapped_data = {datum['campaign_id']: {'clicked_total': datum['clicked_total'], 'items_total': datum['items_total']} for datum in clicked_data}
|
||||
|
||||
for campaign in self:
|
||||
campaign_items_values = mapped_data.get(campaign.id, {})
|
||||
|
||||
@@ -385,6 +385,7 @@
|
||||
'default_user_id': uid,
|
||||
}
|
||||
</field>
|
||||
<field name="domain">[('mailing_type', '=', 'mail')]</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
Create a new mailing
|
||||
@@ -416,28 +417,6 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_create_ab_mass_mailings_from_campaign" model="ir.actions.act_window">
|
||||
<field name="name">Mailings</field>
|
||||
<field name="res_model">mailing.mailing</field>
|
||||
<field name="view_mode">form,kanban,tree</field>
|
||||
<field name="context">{
|
||||
'search_default_assigned_to_me': 1,
|
||||
'search_default_campaign_id': [active_id],
|
||||
'default_campaign_id': active_id,
|
||||
'default_contact_ab_pc': 10,
|
||||
'default_user_id': uid,
|
||||
}
|
||||
</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
Create a new mailing
|
||||
</p><p>
|
||||
You don't need to import your mailing lists, you can easily
|
||||
send emails<br/> to any contact saved in other Odoo apps.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem name="Mailings" id="mass_mailing_menu"
|
||||
parent="mass_mailing_menu_root"
|
||||
sequence="1"
|
||||
|
||||
@@ -5,35 +5,30 @@
|
||||
<field name="model">utm.campaign</field>
|
||||
<field name="inherit_id" ref="utm.utm_campaign_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//sheet" position="before">
|
||||
<header style="min-height:31px;">
|
||||
<button name="%(action_create_mass_mailings_from_campaign)d" type="action" class="oe_highlight" string="Create a mailing"/>
|
||||
<button name="%(action_create_ab_mass_mailings_from_campaign)d" type="action" class="btn-secondary" string="Create an A/B Testing Mailing"/>
|
||||
<span><field name="stage_id" widget="statusbar" options="{'clickable': '1'}"/></span>
|
||||
</header>
|
||||
<xpath expr="//header" position="inside">
|
||||
<button name="%(action_create_mass_mailings_from_campaign)d" type="action" class="oe_highlight" groups="mass_mailing.group_mass_mailing_campaign" string="Send new Mailing"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
|
||||
<button name="%(action_view_mass_mailings_from_campaign)d"
|
||||
type="action" class="oe_stat_button order-11" icon="fa-envelope-o">
|
||||
<field name="mailing_items" widget="statinfo" string="Mailings"/>
|
||||
type="action" class="oe_stat_button order-9" icon="fa-envelope-o"
|
||||
attrs="{'invisible': [('mailing_mail_count', '=', 0)]}" groups="mass_mailing.group_mass_mailing_campaign">
|
||||
<field name="mailing_mail_count" widget="statinfo" string="Mailings"/>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//notebook" position="inside">
|
||||
<page string="Mailings" attrs="{}">
|
||||
<group groups="base.group_no_one">
|
||||
<field name="mailing_ids" readonly="1" nolabel="1">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="sent_date"/>
|
||||
<field name="state"/>
|
||||
<field name="delivered"/>
|
||||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
<button name="action_duplicate" type="object" string="Duplicate"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<page string="Mailings" attrs="{'invisible': [('mailing_mail_count', '=', 0)]}">
|
||||
<field name="mailing_mail_ids" readonly="1" nolabel="1">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="sent_date"/>
|
||||
<field name="state"/>
|
||||
<field name="delivered"/>
|
||||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
<button name="action_duplicate" type="object" string="Duplicate"/>
|
||||
</tree>
|
||||
</field>
|
||||
<div class="o_utm_campaign_mass_mailing_substats d-flex justify-content-end align-items-center">
|
||||
<div class="d-flex justify-content-end align-items-center flex-column">
|
||||
<label for="received_ratio" string="Delivered" class="m-0"/>
|
||||
@@ -83,19 +78,19 @@
|
||||
<field name="inherit_id" ref="utm.utm_campaign_view_kanban"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='user_id']" position="after">
|
||||
<field name="mailing_ids"/>
|
||||
<field name="mailing_mail_ids"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('o_kanban_record_headings')]">
|
||||
<a name="%(action_view_mass_mailings_from_campaign)d" type="action"
|
||||
class="oe_mailings o_kanban_record_subtitle d-inline-block">
|
||||
<t t-raw="record.mailing_ids.raw_value.length"/> Mailings
|
||||
<t t-raw="record.mailing_mail_ids.raw_value.length"/> Mailings
|
||||
</a>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_utm_campaigns" model="ir.actions.act_window">
|
||||
<field name="name">UTM Campaigns</field>
|
||||
<field name="name">Campaigns</field>
|
||||
<field name="res_model">utm.campaign</field>
|
||||
<field name="view_mode">kanban,tree,form</field>
|
||||
<field name="help" type="html">
|
||||
@@ -117,7 +112,7 @@
|
||||
parent="mass_mailing_configuration" sequence="1"
|
||||
groups="mass_mailing.group_mass_mailing_campaign"
|
||||
action="utm.action_view_utm_stage"/>
|
||||
|
||||
|
||||
<menuitem id="mass_mailing_tag_menu"
|
||||
parent="mass_mailing_configuration"
|
||||
action="utm.action_view_utm_tag"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<odoo>
|
||||
<!-- UTM Stage -->
|
||||
<record id="default_utm_stage" model="utm.stage">
|
||||
<field name="name">Default</field>
|
||||
<field name="name">New</field>
|
||||
<field name="sequence">10</field>
|
||||
</record>
|
||||
<record id="campaign_stage_1" model="utm.stage">
|
||||
|
||||
Reference in New Issue
Block a user