[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) <nim@odoo.com>
Signed-off-by: Achraf <abz-odoo@users.noreply.github.com>
This commit is contained in:
Achraf (abz)
2020-11-06 13:01:29 +00:00
parent 0081ff91e3
commit f982d94cfb
+10 -6
View File
@@ -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']