diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index 255b6d55a50..0c9a1a65432 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -64,22 +64,12 @@ class mail_notification(osv.Model): 'read': False, } - def init(self, cr): - """ Set a postgresql NOT NULL constraint with default value false for - the read column. The reason is that when writing in this table using - partner_ids of mail.message model, it bypasses the ORM default - values, leading to 'None' values for read field. This broke the - needaction mechanism for mail.message. """ - cr.execute("ALTER TABLE mail_notification ALTER read SET NOT NULL") - cr.execute("ALTER TABLE mail_notification ALTER read SET DEFAULT false") - def create(self, cr, uid, vals, context=None): """ Override of create to check that we can not create a notification for a message the user can not read. """ if self.pool.get('mail.message').check_access_rights(cr, uid, 'read'): return super(mail_notification, self).create(cr, uid, vals, context=context) - else: - return False + return False def notify(self, cr, uid, partner_ids, msg_id, context=None): """ Send by email the notification depending on the user preferences """ diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 6c47e0006c9..97473886e1a 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -78,14 +78,15 @@ class mail_message(osv.Model): def _search_unread(self, cr, uid, obj, name, domain, context=None): """ Search for messages unread by the current user. """ read_value = not domain[0][2] + read_cond = '' if read_value else '!= true' partner_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id cr.execute(""" SELECT mail_message.id \ FROM mail_message \ JOIN mail_notification ON ( \ mail_notification.message_id = mail_message.id ) \ - WHERE mail_notification.partner_id = %s AND \ - mail_notification.read = %s \ - """ % (partner_id, read_value) ) + WHERE mail_notification.partner_id = %%s AND \ + mail_notification.read %s \ + """ % read_cond, (partner_id,) ) res = cr.fetchall() message_ids = [r[0] for r in res] return [('id', 'in', message_ids)]