From f555bfeca3703cef9cd76120744c58c640a1f0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Doll=C3=A9?= Date: Wed, 16 May 2018 12:53:32 +0200 Subject: [PATCH] [FIX] mail: correctly filter needaction on unread notifications in message_format Previously to this commit needaction used by JS was not taking into account read notifications. It means notably Inbox counter could be higher than expected as taking into account read messages while Inbox displays only unread messages. This commit fixes that by checking notification state when giving needaction_partner_ids to message_format result. This fix has a small impact on performances as message_format is used in notification process for chat or push. A better implementation of message format and its postprocess could probably lessen this fix impact. As we target stable version we avoid rewriting other part of the code. Optimization will be done in development version. Related to task ID 1841243. This is a manual forward port of commit 69714fbeee479cd3e0f89de39b3687c183791fc0 done in saas-11.2. --- addons/mail/models/mail_message.py | 2 +- addons/test_mail/tests/test_performance.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 45d66dac6a5..1a69aaa229a 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -402,7 +402,6 @@ class Message(models.Model): 'message_type', 'subtype_id', 'subject', # message specific 'model', 'res_id', 'record_name', # document related 'channel_ids', 'partner_ids', # recipients - 'needaction_partner_ids', # list of partner ids for whom the message is a needaction 'starred_partner_ids', # list of partner ids for whom the message is starred ]) message_tree = dict((m.id, m) for m in self.sudo()) @@ -418,6 +417,7 @@ class Message(models.Model): note_id = self.env['ir.model.data'].xmlid_to_res_id('mail.mt_note') for message in message_values: + message['needaction_partner_ids'] = self.env['mail.notification'].sudo().search([('mail_message_id', '=', message['id']), ('is_read', '=', False)]).mapped('res_partner_id').ids message['is_note'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['id'] == note_id message['is_discussion'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['id'] == com_id message['is_notification'] = message['is_note'] and not message['model'] and not message['res_id'] diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index b850fdd9227..1e8b594e462 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -206,7 +206,7 @@ class TestAdvMailPerformance(TransactionCase): def test_message_assignation_inbox(self): record = self.env['mail.test.track'].create({'name': 'Test'}) - with self.assertQueryCount(margin=1, admin=42, emp=55): # test_mail only: 42 - 55 + with self.assertQueryCount(margin=1, admin=44, emp=55): # test_mail only: 44 - 55 record.write({ 'user_id': self.user_test.id, }) @@ -262,7 +262,7 @@ class TestAdvMailPerformance(TransactionCase): def test_message_post_one_inbox_notification(self): record = self.env['mail.test.simple'].create({'name': 'Test'}) - with self.assertQueryCount(margin=1, admin=37, emp=48): # com runbot 35 - 46 // test_mail only: 37 - 48 + with self.assertQueryCount(margin=1, admin=39, emp=48): # com runbot 37 - 46 // test_mail only: 39 - 48 record.message_post( body='

Test Post Performances with an inbox ping

', partner_ids=self.user_test.partner_id.ids, @@ -472,7 +472,7 @@ class TestHeavyMailPerformance(TransactionCase): }) self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id) - with self.assertQueryCount(admin=67, emp=87): # com runbot: 66 - 86 // test_mail only: 67 - 87 + with self.assertQueryCount(admin=67, emp=85): # com runbot: 66 - 84 // test_mail only: 67 - 85 rec.write({'user_id': self.user_portal.id}) self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)