From 3261157aa311cc29bb18a417ad6b244a070b64a8 Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Thu, 26 Mar 2026 14:11:03 -0500 Subject: [PATCH] [FIX] mail_gateway: Stop using RecordCapturer RecordCapturer is only available in tests; it must be avoided in business models. Adapt the code to use a similar feature. Closes https://github.com/OCA/social/issues/1812 --- mail_gateway/models/mail_message.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mail_gateway/models/mail_message.py b/mail_gateway/models/mail_message.py index 3d2a37e209..bc93927de8 100644 --- a/mail_gateway/models/mail_message.py +++ b/mail_gateway/models/mail_message.py @@ -3,7 +3,6 @@ from odoo import api, fields, models -from odoo.tests import RecordCapturer from odoo.addons.mail.tools.discuss import Store @@ -118,10 +117,10 @@ def _send_to_gateway_thread(self, gateway_channel_id): gateway_channel_id.gateway_token ) channel = self.env["discuss.channel"].browse(chat_id) - with RecordCapturer( - self.env["mail.notification"], [("gateway_channel_id", "=", channel.id)] - ) as capt: - channel.message_post(**self._get_gateway_thread_message_vals()) + messages = channel.message_post(**self._get_gateway_thread_message_vals()) + notification = messages.notification_ids.filtered( + lambda n: n.gateway_channel_id == channel + ) if not self.gateway_type: self.gateway_type = gateway_channel_id.gateway_id.gateway_type notification_vals = { @@ -131,7 +130,6 @@ def _send_to_gateway_thread(self, gateway_channel_id): "notification_type": "gateway", "gateway_type": gateway_channel_id.gateway_id.gateway_type, } - notification = capt.records if notification: # Set the same gateway_message_id for both notifications. # When the webhook is received, both notifications must be updated.