diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index c1ea26218b7..8b3d168af5c 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -1097,6 +1097,17 @@ class HrExpenseSheet(models.Model): # Mail Thread # -------------------------------------------- + def _get_mail_thread_data_attachments(self): + """ + In order to see in the sheet attachment preview the corresponding + expenses' attachments, the latter attachments are added to the fetched data for the sheet record. + """ + self.ensure_one() + res = super()._get_mail_thread_data_attachments() + expense_ids = self.expense_line_ids + expense_attachments = self.env['ir.attachment'].search([('res_id', 'in', expense_ids.ids), ('res_model', '=', 'hr.expense')], order='id desc') + return res | expense_attachments + def _track_subtype(self, init_values): self.ensure_one() if 'state' in init_values and self.state == 'approve': diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index 89b50d9f122..7024d47ec60 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -796,6 +796,7 @@ +
diff --git a/addons/mail/controllers/discuss.py b/addons/mail/controllers/discuss.py index 7e63fa7da9e..85a09d93910 100644 --- a/addons/mail/controllers/discuss.py +++ b/addons/mail/controllers/discuss.py @@ -431,31 +431,8 @@ class DiscussController(http.Controller): @http.route('/mail/thread/data', methods=['POST'], type='json', auth='user') def mail_thread_data(self, thread_model, thread_id, request_list, **kwargs): - res = {'hasWriteAccess': False} thread = request.env[thread_model].with_context(active_test=False).search([('id', '=', thread_id)]) - try: - thread.check_access_rights("write") - thread.check_access_rule("write") - res['hasWriteAccess'] = True - except AccessError: - pass - if 'activities' in request_list: - res['activities'] = thread.activity_ids.activity_format() - 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) - if 'followers' in request_list: - res['followers'] = [{ - 'id': follower.id, - 'partner_id': follower.partner_id.id, - 'name': follower.name, - 'display_name': follower.display_name, - 'email': follower.email, - 'is_active': follower.is_active, - 'partner': follower.partner_id.mail_partner_format()[follower.partner_id], - } for follower in thread.message_follower_ids] - if 'suggestedRecipients' in request_list: - res['suggestedRecipients'] = thread._message_get_suggested_recipients()[thread.id] - return res + return thread._get_mail_thread_data(request_list) @http.route('/mail/thread/messages', methods=['POST'], type='json', auth='user') def mail_thread_messages(self, thread_model, thread_id, max_id=None, min_id=None, limit=30, **kwargs): diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 69355b49598..a670c459195 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -25,7 +25,7 @@ from xmlrpc import client as xmlrpclib from markupsafe import Markup from odoo import _, api, exceptions, fields, models, tools, registry, SUPERUSER_ID, Command -from odoo.exceptions import MissingError +from odoo.exceptions import MissingError, AccessError from odoo.osv import expression from odoo.tools import is_html_empty from odoo.tools.misc import clean_context, split_every @@ -3142,3 +3142,34 @@ class MailThread(models.AbstractModel): if 'company_id' in self: return self.company_id return False + + def _get_mail_thread_data_attachments(self): + self.ensure_one() + return self.env['ir.attachment'].search([('res_id', '=', self.id), ('res_model', '=', self._name)], order='id desc') + + def _get_mail_thread_data(self, request_list): + self.ensure_one() + res = {'hasWriteAccess': False} + try: + self.check_access_rights("write") + self.check_access_rule("write") + res['hasWriteAccess'] = True + except AccessError: + pass + if 'activities' in request_list: + res['activities'] = self.activity_ids.activity_format() + if 'attachments' in request_list: + res['attachments'] = self._get_mail_thread_data_attachments()._attachment_format(commands=True) + if 'followers' in request_list: + res['followers'] = [{ + 'id': follower.id, + 'partner_id': follower.partner_id.id, + 'name': follower.name, + 'display_name': follower.display_name, + 'email': follower.email, + 'is_active': follower.is_active, + 'partner': follower.partner_id.mail_partner_format()[follower.partner_id], + } for follower in self.message_follower_ids] + if 'suggestedRecipients' in request_list: + res['suggestedRecipients'] = self._message_get_suggested_recipients()[self.id] + return res