odex25_standard/odex25_takaful/odex_takaful/controllers/mail_controller.py

30 lines
1.3 KiB
Python

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