Skip to content
Snippets Groups Projects
Commit 228df6a2 authored by Jairo Llopis's avatar Jairo Llopis Committed by Thibault Delavallée
Browse files

[FIX] link_tracker: do not die if statistic was unlinked when the user clicks on a tracked link

[There's a chance mail statistics disappear](https://github.com/odoo/odoo/blob/b3b8a471cc3e02488dcc0da991fd1d828978220d/addons/mass_mailing/models/mass_mailing.py#L519), which is probably not a very good decision, but there it is. Then, `add_click()` produces a 500 error when a user clicks on the mass mailing if the email comes from an old attempt.

Fix is to check the statistic record effectively exists before linking it.

Closes #22447.
parent 51acdeba
Branches
Tags
No related merge requests found
......@@ -251,16 +251,18 @@ class link_tracker_click(models.Model):
'create_date': datetime.date.today(),
'ip': ip,
'country_id': country_record.id,
'mail_stat_id': stat_id
}
if stat_id:
mail_stat = self.env['mail.mail.statistics'].search([('id', '=', stat_id)])
# It could happen that the related ID is no longer available, but we still want the link to work
if mail_stat.exists():
vals['mail_stat_id'] = stat_id
if mail_stat.mass_mailing_campaign_id:
vals['mass_mailing_campaign_id'] = mail_stat.mass_mailing_campaign_id.id
if mail_stat.mass_mailing_campaign_id:
vals['mass_mailing_campaign_id'] = mail_stat.mass_mailing_campaign_id.id
if mail_stat.mass_mailing_id:
vals['mass_mailing_id'] = mail_stat.mass_mailing_id.id
if mail_stat.mass_mailing_id:
vals['mass_mailing_id'] = mail_stat.mass_mailing_id.id
self.create(vals)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment