[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
This commit is contained in:
Olivier Dony 2012-08-29 18:46:14 +02:00
parent 9b6379462b
commit d8c65aa88e
2 changed files with 5 additions and 14 deletions

View File

@ -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 """

View File

@ -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)]