From a293a948a68805ee2fff5c0a57116abcd870c3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 28 Nov 2012 16:19:39 +0100 Subject: [PATCH] [IMP] mail: when starring a message, create an unread notification if it does not exist; otherwise, set the notification as unread. bzr revid: tde@openerp.com-20121128151939-v24cfx8k2aul8veg --- addons/mail/mail_message.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index ba6d101541c..3273870f5e0 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -206,6 +206,14 @@ class mail_message(osv.Model): new_is_favorite = not (uid in message.get('favorite_user_ids')) if new_is_favorite: self.write(cr, SUPERUSER_ID, message.get('id'), {'favorite_user_ids': [(4, uid)]}, context=context) + # when setting a favorite, set the related notification as unread, or create an unread notification if not existing + notification_obj = self.pool.get('mail.notification') + pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=None)['partner_id'][0] + notif_id = notification_obj.search(cr, SUPERUSER_ID, [('message_id', '=', message.get('id')), ('partner_id', '=', pid)], context=context) + if notif_id: + notification_obj.write(cr, SUPERUSER_ID, notif_id, {'read': False}, context=context) + else: + notification_obj.create(cr, SUPERUSER_ID, {'message_id': message.get('id'), 'partner_id': pid, 'read': False}, context=context) else: self.write(cr, SUPERUSER_ID, message.get('id'), {'favorite_user_ids': [(3, uid)]}, context=context) return new_is_favorite or False