[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.
This commit is contained in:
committed by
Thibault Delavallée
parent
51acdeba4f
commit
228df6a29f
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user