[IMP] mail: simplify partner in _message_read_dict_postprocess
This makes the method easier to follow and does not increase the query count. Part of task-2180311 PR: #43841
This commit is contained in:
@@ -951,23 +951,16 @@ class Message(models.Model):
|
||||
"""
|
||||
safari = request and request.httprequest.user_agent.browser == 'safari'
|
||||
|
||||
# 1. Aggregate partners (author_id and partner_ids) and tracking values
|
||||
partners = self.env['res.partner'].sudo()
|
||||
# 1. Aggregate notifications
|
||||
message_ids = list(message_tree.keys())
|
||||
email_notification_tree = {}
|
||||
for message in message_tree.values():
|
||||
if message.author_id:
|
||||
partners |= message.author_id
|
||||
# find all notified partners
|
||||
email_notification_tree[message.id] = message.notification_ids.filtered(
|
||||
lambda n: n.notification_type == 'email' and n.res_partner_id.active and
|
||||
(n.notification_status in ('bounce', 'exception', 'canceled') or n.res_partner_id.partner_share))
|
||||
partners |= self.env['mail.notification'].concat(*email_notification_tree.values()).mapped('res_partner_id')
|
||||
# Read partners as SUPERUSER -> message being browsed as SUPERUSER it is already the case
|
||||
partners_names = partners.name_get()
|
||||
partner_tree = dict((partner[0], partner) for partner in partners_names)
|
||||
|
||||
# 2. Tracking values
|
||||
# 2. Aggregate tracking values
|
||||
tracking_values = self.env['mail.tracking.value'].sudo().search([('mail_message_id', 'in', message_ids)])
|
||||
message_to_tracking = dict()
|
||||
tracking_tree = dict.fromkeys(tracking_values.ids, False)
|
||||
@@ -987,8 +980,10 @@ class Message(models.Model):
|
||||
for message_dict in messages:
|
||||
message_id = message_dict.get('id')
|
||||
message = message_tree[message_id]
|
||||
|
||||
# Author
|
||||
if message.author_id:
|
||||
author = partner_tree[message.author_id.id]
|
||||
author = (message.author_id.id, message.author_id.display_name)
|
||||
else:
|
||||
author = (0, message.email_from)
|
||||
customer_email_status = (
|
||||
@@ -999,7 +994,8 @@ class Message(models.Model):
|
||||
)
|
||||
customer_email_data = []
|
||||
for notification in email_notification_tree[message.id]:
|
||||
customer_email_data.append((partner_tree[notification.res_partner_id.id][0], partner_tree[notification.res_partner_id.id][1], notification.notification_status))
|
||||
partner_name_get = notification.res_partner_id.name_get()[0]
|
||||
customer_email_data.append((partner_name_get[0], partner_name_get[1], notification.notification_status))
|
||||
|
||||
# Attachments
|
||||
main_attachment = self.env['ir.attachment']
|
||||
|
||||
Reference in New Issue
Block a user