From 69714fbeee479cd3e0f89de39b3687c183791fc0 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. --- addons/mail/models/mail_message.py | 2 +- addons/test_mail/tests/test_performance.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 89e4237c8e1..cee1c692632 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -401,7 +401,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()) @@ -414,6 +413,7 @@ class Message(models.Model): subtypes_dict = dict((subtype['id'], subtype) for subtype in subtypes) xml_comment_id = self.env.ref('mail.mt_comment').id 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]]['internal'] message['is_discussion'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['id'] == xml_comment_id message['subtype_description'] = message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['description'] diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index d6e272bf0aa..f4c006c9662 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -167,7 +167,7 @@ class TestAdvMailPerformance(TransactionCase): 'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id, }) - with self.assertQueryCount(margin=1, admin=84, emp=115): # com runbot 84 - 116 // test_mail only: 68 - 96 + with self.assertQueryCount(margin=1, admin=86, emp=115): # com runbot 86 - 116 // test_mail only: 70 - 96 activity.action_feedback(feedback='Zizisse Done !') @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @@ -207,7 +207,7 @@ class TestAdvMailPerformance(TransactionCase): def test_message_log_with_post(self): record = self.env['mail.test.simple'].create({'name': 'Test'}) - with self.assertQueryCount(admin=31, emp=43): # test_mail only: 29 - 40 + with self.assertQueryCount(admin=33, emp=46): # com runbot: 33 - 43 // test_mail only: 31 - 43 record.message_post( body='

Test message_post as log

', subtype='mail.mt_note', @@ -218,7 +218,7 @@ class TestAdvMailPerformance(TransactionCase): def test_message_post_no_notification(self): record = self.env['mail.test.simple'].create({'name': 'Test'}) - with self.assertQueryCount(admin=31, emp=43): # test_mail only: 29 - 40 + with self.assertQueryCount(admin=33, emp=46): # com runbot: 33 - 43 // test_mail only: 31 - 43 record.message_post( body='

Test Post Performances basic

', partner_ids=[], @@ -231,7 +231,7 @@ class TestAdvMailPerformance(TransactionCase): def test_message_post_one_email_notification(self): record = self.env['mail.test.simple'].create({'name': 'Test'}) - with self.assertQueryCount(margin=1, admin=85, emp=114): # com runbot 83 - 112 // test_mail only: 81 - 110 + with self.assertQueryCount(margin=1, admin=87, emp=116): # com runbot 85 - 112 // test_mail only: 83 - 112 record.message_post( body='

Test Post Performances with an email ping

', partner_ids=self.customer.ids, @@ -243,7 +243,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=44, emp=57): # com runbot 42 - 55 // test_mail only: 42 - 55 + with self.assertQueryCount(margin=1, admin=46, emp=59): # com runbot 44 - 55 // test_mail only: 44 - 57 record.message_post( body='

Test Post Performances with an inbox ping

', partner_ids=self.user_test.partner_id.ids, @@ -366,7 +366,7 @@ class TestHeavyMailPerformance(TransactionCase): self.umbrella.message_subscribe(self.user_portal.partner_id.ids) record = self.umbrella.sudo(self.env.user) - with self.assertQueryCount(admin=124, emp=157): # com runbot 122 - 155 // test_mail only: 118 - 150 + with self.assertQueryCount(admin=126, emp=161): # com runbot 124 - 155 // test_mail only: 120 - 154 record.message_post( body='

Test Post Performances

', message_type='comment', @@ -383,7 +383,7 @@ class TestHeavyMailPerformance(TransactionCase): record = self.umbrella.sudo(self.env.user) template_id = self.env.ref('test_mail.mail_test_tpl').id - with self.assertQueryCount(admin=149, emp=197): # com runbot 147 - 195 // test_mail only: 141 - 187 + with self.assertQueryCount(admin=151, emp=201): # com runbot 149 - 195 // test_mail only: 143 - 191 record.message_post_with_template(template_id, message_type='comment', composition_mode='comment') self.assertEqual(record.message_ids[0].body, '

Adding stuff on %s

' % record.name) @@ -478,7 +478,7 @@ class TestHeavyMailPerformance(TransactionCase): customer_id = self.customer.id user_id = self.user_portal.id - with self.assertQueryCount(admin=325, emp=389): # test_mail only: 308 - 368 + with self.assertQueryCount(admin=327, emp=389): # test_mail only: 310 - 368 rec = self.env['mail.test.full'].create({ 'name': 'Test', 'umbrella_id': umbrella_id, @@ -507,7 +507,7 @@ class TestHeavyMailPerformance(TransactionCase): }) self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id) - with self.assertQueryCount(admin=236, emp=275): # test_mail only: 230 - 268 + with self.assertQueryCount(admin=238, emp=275): # test_mail only: 232 - 268 rec.write({ 'name': 'Test2', 'umbrella_id': self.umbrella.id, @@ -545,7 +545,7 @@ class TestHeavyMailPerformance(TransactionCase): }) self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id) - with self.assertQueryCount(admin=239, emp=279): # test_mail only: 233 - 271 + with self.assertQueryCount(admin=241, emp=279): # test_mail only: 235 - 271 rec.write({ 'name': 'Test2', 'umbrella_id': umbrella_id,