[IMP] mail_message: notification_ids as _auto_join; mail_thread: mail_message as _auto_join. Updated search domain of function fields accordingly.

bzr revid: tde@openerp.com-20121204145645-vea4i1p93zmwztqx
This commit is contained in:
Thibault Delavallée 2012-12-04 15:56:45 +01:00
parent 690db185c6
commit 83d1e7cdf2
3 changed files with 5 additions and 25 deletions

View File

@ -98,15 +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. """
if domain[0][2]:
read_cond = "(read = False OR read IS NULL)"
else:
read_cond = "read = True"
partner_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
cr.execute("SELECT message_id FROM mail_notification "\
"WHERE partner_id = %%s AND %s" % read_cond,
(partner_id,))
return [('id', 'in', [r[0] for r in cr.fetchall()])]
return ['&', ('notification_ids.partner_id.user_ids', 'in', [uid]), ('notification_ids.read', '=', not domain[0][2])]
def name_get(self, cr, uid, ids, context=None):
# name_get may receive int id instead of an id list
@ -146,7 +138,7 @@ class mail_message(osv.Model):
store=True, string='Message Record Name',
help="Name get of the related document."),
'notification_ids': fields.one2many('mail.notification', 'message_id',
string='Notifications',
string='Notifications', _auto_join=True,
help='Technical field holding the message notifications. Use notified_partner_ids to access notified partners.'),
'subject': fields.char('Subject'),
'date': fields.datetime('Date'),
@ -166,9 +158,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]

View File

@ -122,17 +122,7 @@ class mail_thread(osv.AbstractModel):
return res
def _search_unread(self, cr, uid, obj=None, name=None, domain=None, context=None):
partner_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
res = {}
notif_obj = self.pool.get('mail.notification')
notif_ids = notif_obj.search(cr, uid, [
('partner_id', '=', partner_id),
('message_id.model', '=', self._name),
('read', '=', False)
], context=context)
for notif in notif_obj.browse(cr, uid, notif_ids, context=context):
res[notif.message_id.res_id] = True
return [('id', 'in', res.keys())]
return ['&', ('message_ids.model', '=', self._name), ('message_ids.notification_ids.to_read', '=', False)]
def _get_followers(self, cr, uid, ids, name, arg, context=None):
fol_obj = self.pool.get('mail.followers')
@ -207,6 +197,7 @@ class mail_thread(osv.AbstractModel):
help="Comments and emails"),
'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, fnct_search=_search_unread,

View File

@ -11,7 +11,6 @@
}</field>
<field name="params" eval="&quot;{
'domain': [
('notification_ids.partner_id.user_ids', 'in', [uid]),
('to_read', '=', True),
('favorite_user_ids', 'not in', [uid])
],