[IMP] link_tracker: add global click count on campaign

Having a global click ratio on the campaign was pointless considering the
nature of the social.app and its posts. Therefore, we decided to have a
global click count which gives a better idea of the popularity of the campaign
itself.

Task ID 2074813 (FP request UTM refactor)
PR: #37185
This commit is contained in:
qmo-odoo
2019-09-20 14:19:36 +00:00
committed by Thibault Delavallée
parent 1692d1ff3e
commit ecd93e6639
2 changed files with 19 additions and 5 deletions
+13 -2
View File
@@ -11,11 +11,22 @@ class UtmCampaign(models.Model):
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):
click_data = self.env['link.tracker.click'].read_group(
[('campaign_id', 'in', self.ids)],
['campaign_id'], ['campaign_id'])
mapped_data = {datum['campaign_id'][0]: datum['campaign_id_count'] for datum in click_data}
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 = False
self.items_total = False
self.clicked_total = 0
self.items_total = 0
@api.depends('items_total', 'clicked_total')
def _compute_clicks_ratio(self):
@@ -7,8 +7,8 @@
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button name="%(link_tracker_action_campaign)d"
type="action" class="oe_stat_button order-12">
<field name="clicks_ratio" widget="percentpie" string="Clicks"/>
type="action" class="oe_stat_button order-12" icon="fa-mouse-pointer">
<field name="click_count" widget="statinfo" string="Clicks"/>
</button>
</xpath>
</field>
@@ -19,9 +19,12 @@
<field name="model">utm.campaign</field>
<field name="inherit_id" ref="utm.utm_campaign_view_kanban"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='stage_id']" position="after">
<field name="click_count"/>
</xpath>
<xpath expr="//div[@id='utm_statistics']" position="inside">
<div class="d-flex justify-content-between align-items-center w-100 order-1 mb-1">
<strong>Clicks</strong> <span><field name="clicks_ratio"/> %</span>
<strong>Clicks</strong> <span><t t-esc="record.click_count.raw_value"/></span>
</div>
</xpath>
</field>