From 4b68f64473ff12ae66d880d3e4a764cbbd2a0053 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Tue, 18 Sep 2012 14:17:31 +0530 Subject: [PATCH 1/5] [ADD] add context to client action and improve read method for set read message by user. bzr revid: nco@tinyerp.com-20120918084731-eed2ssuzhw7woi78 --- addons/mail/mail_group.py | 2 +- addons/mail/mail_group_view.xml | 1 + addons/mail/mail_message.py | 7 +++++++ addons/mail/mail_message_view.xml | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index fe0cc3950ae..c7c51a84a00 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -125,7 +125,7 @@ class mail_group(osv.Model): params = { 'search_view_id': search_ref and search_ref[1] or False, 'domain': [('model', '=', 'mail.group'), ('res_id', '=', mail_group_id)], - 'context': {'default_model': 'mail.group', 'default_res_id': mail_group_id}, + 'context': {'default_model': 'mail.group', 'default_res_id': mail_group_id, 'mail_keep_unread':True}, 'res_model': 'mail.message', 'thread_level': 1, } diff --git a/addons/mail/mail_group_view.xml b/addons/mail/mail_group_view.xml index 31beba80ecc..bcd754fed3d 100644 --- a/addons/mail/mail_group_view.xml +++ b/addons/mail/mail_group_view.xml @@ -6,6 +6,7 @@ Discussion Group mail.wall mail.message + {'mail_keep_unread': True} diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 44ce76b94b0..c9340b77cea 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -218,10 +218,17 @@ class mail_message(osv.Model): """ limit = limit or self._message_read_limit context = context or {} + notif_obj = self.pool.get("mail.notification") if not ids: ids = self.search(cr, uid, domain, context=context, limit=limit) messages = self.browse(cr, uid, ids, context=context) + partner_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id + for msg in messages: + notif_ids = notif_obj.search(cr, uid, [('partner_id', '=', partner_id), ('message_id', '=', msg.id)], context=context) + notif_obj.write(cr, uid, notif_ids, {'read': True}, context=context) + context.update({'mail_keep_unread':False}) + result = [] tree = {} # key: ID, value: record for msg in messages: diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index 914937a34f3..c9806a9db9a 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -91,14 +91,14 @@ News Feed mail.wall + 'context': {'default_model': 'res.users', 'default_res_id': uid, 'mail_keep_unread': True} }""/> My Feeds mail.wall + 'context': {'default_model': 'res.users', 'default_res_id': uid, 'mail_keep_unread': True} }""/> From bbf40f3d7eda6e84b012105eb8b5571bd26d177d Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Tue, 18 Sep 2012 17:53:59 +0530 Subject: [PATCH 2/5] [IMP] impove the read message to set msg read. bzr revid: nco@tinyerp.com-20120918122359-uppqkoba9xxj8jst --- addons/mail/mail_message.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index c9340b77cea..ae04d81ee4b 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -223,15 +223,12 @@ class mail_message(osv.Model): ids = self.search(cr, uid, domain, context=context, limit=limit) messages = self.browse(cr, uid, ids, context=context) - partner_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id - for msg in messages: - notif_ids = notif_obj.search(cr, uid, [('partner_id', '=', partner_id), ('message_id', '=', msg.id)], context=context) - notif_obj.write(cr, uid, notif_ids, {'read': True}, context=context) - context.update({'mail_keep_unread':False}) - result = [] tree = {} # key: ID, value: record for msg in messages: + if not context.has_key('mail_keep_unread'): + notif_ids = notif_obj.search(cr, uid, [('message_id', '=', msg.id)], context=context) + notif_obj.write(cr, uid, notif_ids, {'read': True}, context=context) if len(result) < (limit - 1): record = self._message_dict_get(cr, uid, msg, context=context) if thread_level and msg.parent_id: From 10107c6ce6293b714c5b821c628e6f83ea80ed24 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Wed, 19 Sep 2012 14:01:23 +0530 Subject: [PATCH 3/5] [ADD] add unit test for message read. bzr revid: nco@tinyerp.com-20120919083123-mmbwbpc3w3oszptg --- addons/mail/tests/test_mail.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index 57a59e2595f..a90d17913bd 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -677,3 +677,30 @@ class test_mail(TestMailMockups): msg1.refresh() # Test: msg1 has Bert as voter self.assertEqual(set(msg1.vote_user_ids), set([user_bert]), 'after unvoting for Admin, Bert is not the voter') + + def test_70_read_unread(self): + """ Test designed for the message read or unread feature. """ + cr, uid = self.cr, self.uid + group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) + user_admin = self.res_users.browse(cr, uid, uid) + + # 0 - Admin + p_a_id = user_admin.partner_id.id + # 1 - Bert Tartopoils, with email, should receive emails for comments and emails + p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b'}) + # 2 - Carine Poilvache, with email, should never receive emails + p_c_id = self.res_partner.create(cr, uid, {'name': 'Carine Poilvache', 'email': 'c@c', 'notification_email_send': 'email'}) + # 3 - Dédé Grosbedon, without email, to test email verification; should receive emails for every message + p_d_id = self.res_partner.create(cr, uid, {'name': 'Dédé Grosbedon', 'notification_email_send': 'all'}) + + # Subscribe #1, #2 + group_pigs.message_subscribe([p_b_id, p_c_id]) + + msg1 = group_pigs.message_post(body='My Body', subject='1') + context = {'default_model': 'mail.group', 'default_res_id': [self.group_pigs_id]} + self.mail_message.message_read(cr, uid, ids=False, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], thread_level=2, limit=10,context=context) + if not context.has_key('mail_keep_unread'): + notif_ids = self.mail_notification.search(cr, uid, [('partner_id', '=', user_admin.partner_id.id),('message_id', '=', msg1)], context=context) + na_count = len(notif_ids) + self.assertTrue(len(notif_ids), 'unread notifications') + self.mail_notification.write(cr, uid, notif_ids, {'read': True}, context=context) From 6c53c3c38b339f830d96e737c92f69a757bf2267 Mon Sep 17 00:00:00 2001 From: "Atul Patel (OpenERP)" Date: Fri, 21 Sep 2012 17:50:11 +0530 Subject: [PATCH 4/5] [FIX]: Fix none context problem bzr revid: atp@tinyerp.com-20120921122011-xmxm32ow5lnwc4al --- addons/mail/tests/test_mail.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index 25767047269..5d3a100f09b 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -694,18 +694,18 @@ class test_mail(TestMailMockups): msg2 = group_pigs.message_post(body='My Body', subject='2') message1 = self.mail_message.browse(cr, uid, msg1) message2 = self.mail_message.browse(cr, uid, msg2) - + context= {} #Test : Groups contain two messages. self.assertEqual(2, len(group_pigs.message_ids), 'group should contain 2 messages') #Read message without key. using bert parner - msg_data1 = self.mail_message.message_read(cr, user_bert.id, ids=[message1.id], domain=[], thread_level=2, limit=10,context={}) + msg_data1 = self.mail_message.message_read(cr, user_bert.id, ids=[message1.id], domain=[], thread_level=2, limit=10,context=context) #check notification For message readable or unread. notif_msg1_ids1 = self.mail_notification.search(cr, uid, [('partner_id', '=', user_bert.partner_id.id),('message_id', '=', message1.id)], context=context) notif_data1 = self.mail_notification.read(cr, uid, notif_msg1_ids1, ['read'])[0]['read'] # Test: Message1 are marked as read. self.assertTrue(notif_data1, 'Message1 are set as read for the user Bert that read it') #Pass key in context for unread message.. - context = {'default_model': 'mail.group', 'default_res_id': [self.group_pigs_id], 'mail_keep_unread': True} + context.update({'default_model': 'mail.group', 'default_res_id': [self.group_pigs_id], 'mail_keep_unread': True}) # Test: New created Message2 are set as unread. msg_data2 = self.mail_message.message_read(cr, uid, ids=[message2.id], domain=[], thread_level=2, limit=10,context=context) #Check Notification For unread message.. From d473364d5269d6b2e26d22ba69d9e054c1a195b2 Mon Sep 17 00:00:00 2001 From: "Atul Patel (OpenERP)" Date: Mon, 24 Sep 2012 10:26:58 +0530 Subject: [PATCH 5/5] [IMP]: Imp test case bzr revid: atp@tinyerp.com-20120924045658-6m1tkjpqm4ztvojf --- addons/mail/tests/test_mail.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index 5d3a100f09b..94ecdc1be46 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -695,6 +695,9 @@ class test_mail(TestMailMockups): message1 = self.mail_message.browse(cr, uid, msg1) message2 = self.mail_message.browse(cr, uid, msg2) context= {} + #Check Before read , number of posted message count are 2. + na_count = self.mail_message._needaction_count(cr, uid, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)]) + self.assertEqual(na_count, 2, 'posted message count does not match needaction count') #Test : Groups contain two messages. self.assertEqual(2, len(group_pigs.message_ids), 'group should contain 2 messages') #Read message without key. using bert parner @@ -712,6 +715,6 @@ class test_mail(TestMailMockups): notif_msg2_ids2 = self.mail_notification.search(cr, uid, [('partner_id', '=', user_admin.partner_id.id),('message_id', '=', message2.id)], context=context) notif_data2 = self.mail_notification.read(cr, uid, notif_msg2_ids2, ['read'])[0]['read'] self.assertFalse(notif_data2, 'Newly created Message2 are set as unread') - # Check there are 1 needaction on mail.message with particular domain + # Check there are 1 needaction after Reading one posted message on mail.message with particular domain. na_count = self.mail_message._needaction_count(cr, uid, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)]) self.assertEqual(na_count, 1, 'posted message count does not match needaction count')