From ecd93e663976a3ce88e1b2b891450656049f411f Mon Sep 17 00:00:00 2001 From: qmo-odoo Date: Fri, 6 Sep 2019 06:36:21 +0000 Subject: [PATCH] [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 --- addons/link_tracker/models/utm.py | 15 +++++++++++++-- addons/link_tracker/views/utm_campaign_views.xml | 9 ++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/addons/link_tracker/models/utm.py b/addons/link_tracker/models/utm.py index 71c94ba4eb6..6d356ad7d5a 100644 --- a/addons/link_tracker/models/utm.py +++ b/addons/link_tracker/models/utm.py @@ -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): diff --git a/addons/link_tracker/views/utm_campaign_views.xml b/addons/link_tracker/views/utm_campaign_views.xml index 2ff5c1c0398..e39c1ec1845 100644 --- a/addons/link_tracker/views/utm_campaign_views.xml +++ b/addons/link_tracker/views/utm_campaign_views.xml @@ -7,8 +7,8 @@ @@ -19,9 +19,12 @@ utm.campaign + + +
- Clicks % + Clicks