From 04a7fbb9c684eddf4200f42c24bf2d84bcd88eda Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Tue, 13 Jan 2026 22:18:57 +0100 Subject: [PATCH] [FIX] odex_takaful --- .../odex_takaful/controllers/__init__.py | 1 + .../controllers/mail_controller.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 odex25_takaful/odex_takaful/controllers/mail_controller.py diff --git a/odex25_takaful/odex_takaful/controllers/__init__.py b/odex25_takaful/odex_takaful/controllers/__init__.py index 058e02b5e..27aeecc20 100644 --- a/odex25_takaful/odex_takaful/controllers/__init__.py +++ b/odex25_takaful/odex_takaful/controllers/__init__.py @@ -2,6 +2,7 @@ from . import _cart_change from . import report_api from . import takaful_api +from . import mail_controller diff --git a/odex25_takaful/odex_takaful/controllers/mail_controller.py b/odex25_takaful/odex_takaful/controllers/mail_controller.py new file mode 100644 index 000000000..69558c8bf --- /dev/null +++ b/odex25_takaful/odex_takaful/controllers/mail_controller.py @@ -0,0 +1,30 @@ +from odoo import http +from odoo.http import request +from odoo.addons.mail.controllers.main import MailController + + +class MailControllerPatch(MailController): + + + @http.route('/mail/thread/data', methods=['POST'], type='json', auth='user') + def mail_thread_data(self, thread_model, thread_id, request_list, **kwargs): + if thread_model != 'res.partner': + return super(MailControllerPatch, self).mail_thread_data(thread_model, thread_id, request_list, **kwargs) + + res = {} + thread = request.env[thread_model].with_context(active_test=False).search([('id', '=', thread_id)]) + + # --- PATCH: Force Singleton --- + # We have patched the search method in res.partner model in path /odex_takaful/models/res_partner.py + # It triggers a singlton error + # We need to get the thread_id of res.partner only + thread = thread.filtered(lambda r: r.id == thread_id) + # ------------------------------ + + if 'attachments' in request_list: + res['attachments'] = thread.env['ir.attachment'].search([ + ('res_id', '=', thread.id), + ('res_model', '=', thread._name) + ], order='id desc')._attachment_format(commands=True) + + return res \ No newline at end of file