diff --git a/addons/link_tracker/models/utm.py b/addons/link_tracker/models/utm.py index 6d356ad7d5a..ebb343472e7 100644 --- a/addons/link_tracker/models/utm.py +++ b/addons/link_tracker/models/utm.py @@ -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 diff --git a/addons/mass_mailing/models/utm.py b/addons/mass_mailing/models/utm.py index 46651b0f1ea..fe98c9c0ee5 100644 --- a/addons/mass_mailing/models/utm.py +++ b/addons/mass_mailing/models/utm.py @@ -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, {}) diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml index 727b295b9a0..d06c64db04f 100644 --- a/addons/mass_mailing/views/mailing_mailing_views.xml +++ b/addons/mass_mailing/views/mailing_mailing_views.xml @@ -385,6 +385,7 @@ 'default_user_id': uid, } + [('mailing_type', '=', 'mail')] Create a new mailing @@ -416,28 +417,6 @@ - - Mailings - mailing.mailing - form,kanban,tree - { - '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, - } - - - - Create a new mailing - - You don't need to import your mailing lists, you can easily - send emails to any contact saved in other Odoo apps. - - - - utm.campaign - - - - - - + + - + 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"> + - - - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -83,19 +78,19 @@ - + - Mailings + Mailings - UTM Campaigns + Campaigns utm.campaign kanban,tree,form @@ -117,7 +112,7 @@ parent="mass_mailing_configuration" sequence="1" groups="mass_mailing.group_mass_mailing_campaign" action="utm.action_view_utm_stage"/> - + - Default + New 10
Create a new mailing @@ -416,28 +417,6 @@
- Create a new mailing -
- You don't need to import your mailing lists, you can easily - send emails to any contact saved in other Odoo apps. -