From d5ccc794e26bec9795025851c27fd56501cc54d9 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 26 Jul 2023 12:44:47 +0200 Subject: [PATCH] [FIX] mail_tracking_mailgun: bounces error Since https://github.com/odoo/odoo/commit/9a47101964a56fe5a7a44da37209e8f67b508395 bouncing the emails through the mailgun controller causes a singleton error when the anonymous user tries to record the bounce message. TT44585 --- mail_tracking_mailgun/models/res_partner.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mail_tracking_mailgun/models/res_partner.py b/mail_tracking_mailgun/models/res_partner.py index 6e201f8e8..b072af8da 100644 --- a/mail_tracking_mailgun/models/res_partner.py +++ b/mail_tracking_mailgun/models/res_partner.py @@ -8,7 +8,7 @@ from urllib.parse import urljoin import requests -from odoo import _, api, models +from odoo import SUPERUSER_ID, _, api, models from odoo.exceptions import UserError @@ -35,6 +35,11 @@ class ResPartner(models.Model): body = _( "Email has been bounced: %(email)s\nReason: %(reason)s\nEvent: %(event_str)s" ) % ({"email": partner.email, "reason": reason, "event_str": event_str}) + # This function can be called by the non user via the callback_method set in + # /mail/tracking/mailgun/all/. A sudo() is not enough to succesfully send + # the bounce message in this circumstances. + if self.env.su: + partner = partner.with_user(SUPERUSER_ID) partner.message_post(body=body) def check_email_validity(self):