From 8003289219b2babc184aba55445f96b99a71c0d9 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 14 Mar 2019 13:10:49 +0000 Subject: [PATCH] [FIX] mail: activity document name=>updated name The activities "Document Name" (res_name) are computed and stored by getting them on original document, so if we change name of original model => the activity names are not updated. Thus the document name we see we showing the "Activity" view is the one that was used when activities were created with an odd heuristic (by inverse order of activity type and max alphabetical value) and not translated. With this changeset we ignore "Document Name" and directly get names of records when display "Activity" view. note: the changeset also filter out activities on document we can reads: this was done when a domain was set but not otherwise so access error could be easily gotten. opw-1949437 closes #31850 Signed-off-by: Nicolas Lempereur (nle) --- addons/mail/models/mail_activity.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index 0b327d59338..982d67b21c7 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -434,19 +434,21 @@ class MailActivity(models.Model): activity_domain.append(('res_id', 'in', res.ids)) grouped_activities = self.env['mail.activity'].read_group( activity_domain, - ['res_id', 'activity_type_id', 'res_name:max(res_name)', 'ids:array_agg(id)', 'date_deadline:min(date_deadline)'], + ['res_id', 'activity_type_id', 'ids:array_agg(id)', 'date_deadline:min(date_deadline)'], ['res_id', 'activity_type_id'], lazy=False) + # filter out unreadable records + if not domain: + res_ids = tuple(a['res_id'] for a in grouped_activities) + res = self.env[res_model].search([('id', 'in', res_ids)]) + grouped_activities = [a for a in grouped_activities if a['res_id'] in res.ids] activity_type_ids = self.env['mail.activity.type'] - res_id_to_name = {} res_id_to_deadline = {} activity_data = defaultdict(dict) for group in grouped_activities: res_id = group['res_id'] - res_name = group['res_name'] activity_type_id = group['activity_type_id'][0] activity_type_ids |= self.env['mail.activity.type'].browse(activity_type_id) # we will get the name when reading mail_template_ids - res_id_to_name[res_id] = res_name res_id_to_deadline[res_id] = group['date_deadline'] if (res_id not in res_id_to_deadline or group['date_deadline'] < res_id_to_deadline[res_id]) else res_id_to_deadline[res_id] state = self._compute_state_from_date(group['date_deadline'], self.user_id.sudo().tz) activity_data[res_id][activity_type_id] = { @@ -456,6 +458,7 @@ class MailActivity(models.Model): 'o_closest_deadline': group['date_deadline'], } res_ids_sorted = sorted(res_id_to_deadline, key=lambda item: res_id_to_deadline[item]) + res_id_to_name = dict(self.env[res_model].browse(res_ids_sorted).name_get()) activity_type_infos = [] for elem in sorted(activity_type_ids, key=lambda item: item.sequence): mail_template_info = []