From f982d94cfb0e9998308866036d616e41f21b9fa9 Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Wed, 4 Nov 2020 11:20:03 +0000 Subject: [PATCH] [FIX] mass_mailing: Create campaign from opportunities Issue - Open any opportunity - Go to "Extra Information" and click on "Campaign" field - try to create new campaign Traceback is raised Cause "self.ids" is empty and the "tuple(self.ids)" on the SQL query return "()" Solution Initialize campaign field with default values opw-2376082 closes odoo/odoo#61476 X-original-commit: 5797be02e32e68e0a188bfdc8b85068fb8fa5435 Signed-off-by: Nicolas Martinelli (nim) Signed-off-by: Achraf --- addons/mass_mailing/models/utm.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/mass_mailing/models/utm.py b/addons/mass_mailing/models/utm.py index 54ea93bf62c..88c99e0f0ea 100644 --- a/addons/mass_mailing/models/utm.py +++ b/addons/mass_mailing/models/utm.py @@ -34,6 +34,15 @@ class UtmCampaign(models.Model): def _compute_statistics(self): """ Compute statistics of the mass mailing campaign """ + default_vals = { + 'received_ratio': 0, + 'opened_ratio': 0, + 'replied_ratio': 0, + 'bounced_ratio': 0 + } + if not self.ids: + self.update(default_vals) + return self.env.cr.execute(""" SELECT c.id as campaign_id, @@ -64,12 +73,7 @@ class UtmCampaign(models.Model): for campaign in self: stats = stats_per_campaign.get(campaign.id) if not stats: - vals = { - 'received_ratio': 0, - 'opened_ratio': 0, - 'replied_ratio': 0, - 'bounced_ratio': 0 - } + vals = default_vals else: total = (stats['expected'] - stats['ignored']) or 1 delivered = stats['sent'] - stats['bounced']