summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2012-08-29 18:46:14 +0200
committerOlivier Dony <odo@openerp.com>2012-08-29 18:46:14 +0200
commitd8c65aa88eb9f779941feae45955fa09aaf8ce11 (patch)
tree9191374c7d7aa560cd804179a7f1c2129d56306c
parent9b6379462be8fd0fc2ec3e3565ccb5b778e6c6bf (diff)
[IMP] mail.notification: simplify model creation + some lint cleanup
No need for extra constraints/defaults, in OpenERP boolean values are `true` and `not true` (false/NULL). This seems to work well with db indexes too. bzr revid: odo@openerp.com-20120829164614-9kqrownb7q4vzrjc
-rw-r--r--addons/mail/mail_followers.py12
-rw-r--r--addons/mail/mail_message.py7
2 files changed, 5 insertions, 14 deletions
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)]