[IMP] mail: message_unread searchable field now returns a domain. This domain is quite complex, because it bypasses limitations of the _auto_join feature used on message_ids. It should be: message_ids.read = False. However, it takes into account the one2many model, as well as to_read being a function field also searchable. Ths parsing is not capable to handle this kind of thing correctly now without using an ugly hack. Updated _search_to_read and _search_starred.

bzr revid: tde@openerp.com-20121129144253-i9e7m2kqjteq8ajr
This commit is contained in:
Thibault Delavallée 2012-11-29 15:42:53 +01:00
parent bb759994ac
commit 9f84bbddfb
3 changed files with 15 additions and 25 deletions

View File

@ -98,8 +98,7 @@ class mail_message(osv.Model):
def _search_to_read(self, cr, uid, obj, name, domain, context=None):
""" Search for messages to read by the current user. Condition is
inversed because we search unread message on a read column. """
pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
return ['&', ('notification_ids.partner_id', '=', pid), ('notification_ids.read', '=', not domain[0][2])]
return ['&', ('notification_ids.partner_id.user_ids', 'in', [uid]), ('notification_ids.read', '=', not domain[0][2])]
def _get_starred(self, cr, uid, ids, name, arg, context=None):
""" Compute if the message is unread by the current user. """
@ -118,8 +117,7 @@ class mail_message(osv.Model):
def _search_starred(self, cr, uid, obj, name, domain, context=None):
""" Search for messages to read by the current user. Condition is
inversed because we search unread message on a read column. """
pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
return ['&', ('notification_ids.partner_id', '=', pid), ('notification_ids.starred', '=', domain[0][2])]
return ['&', ('notification_ids.partner_id.user_ids', 'in', [uid]), ('notification_ids.starred', '=', domain[0][2])]
def name_get(self, cr, uid, ids, context=None):
# name_get may receive int id instead of an id list
@ -179,9 +177,7 @@ class mail_message(osv.Model):
}
def _needaction_domain_get(self, cr, uid, context=None):
if self._needaction:
return [('to_read', '=', True)]
return []
return [('to_read', '=', True)]
def _get_default_author(self, cr, uid, context=None):
return self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
@ -529,15 +525,6 @@ class mail_message(osv.Model):
thread_level=thread_level, message_unload_ids=message_unload_ids, domain=domain, parent_id=parent_id, context=context)
return message_list
# TDE Note: do we need this ?
# def user_free_attachment(self, cr, uid, context=None):
# attachment = self.pool.get('ir.attachment')
# attachment_list = []
# attachment_ids = attachment.search(cr, uid, [('res_model', '=', 'mail.message'), ('create_uid', '=', uid)])
# if len(attachment_ids):
# attachment_list = [{'id': attach.id, 'name': attach.name, 'date': attach.create_date} for attach in attachment.browse(cr, uid, attachment_ids, context=context)]
# return attachment_list
#------------------------------------------------------
# mail_message internals
#------------------------------------------------------

View File

@ -122,14 +122,16 @@ class mail_thread(osv.AbstractModel):
return res
def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None):
user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
cr.execute(""" SELECT DISTINCT m.res_id FROM mail_message m
JOIN mail_notification n
ON (n.message_id = m.id AND n.partner_id = %s AND (n.read = False or n.read IS NULL))
WHERE m.model = %s""",
(user_pid, self._name,))
res_ids = [result[0] for result in cr.fetchall()]
return [('id', 'in', res_ids)]
""" TDE FIXME in 7.1: searching unread messages
_auto_join is currently a very limited feature; therefore the returned
domain to search for unread messages take into acount the following
limitations of this feature :
- does not take into account the domain on the one2many field
(i.e. message_ids.model = self._name is needed)
- does not correctly handle function field on relational table
(i.e. message_ids.read crashes)
"""
return ['&', '&', ('message_ids.model', '=', self._name), ('message_ids.notification_ids.partner_id.user_ids', 'in', [uid]), ('message_ids.notification_ids.read', '=', False)]
def _get_followers(self, cr, uid, ids, name, arg, context=None):
fol_obj = self.pool.get('mail.followers')
@ -200,6 +202,7 @@ class mail_thread(osv.AbstractModel):
obj='res.partner', string='Followers', multi='_get_followers'),
'message_ids': fields.one2many('mail.message', 'res_id',
domain=lambda self: [('model', '=', self._name)],
_auto_join=True,
string='Messages',
help="Messages and communication history"),
'message_unread': fields.function(_get_message_data,

View File

@ -11,7 +11,7 @@
}</field>
<field name="params" eval="&quot;{
'domain': [
('to_read', '=', False),
('to_read', '=', True),
('starred', '=', False),
],
'view_mailbox': True,