diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index aec106f766b..95c34ad5c51 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -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] diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 30954be4ed8..d308105d81e 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -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, diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml index 4106eb2e024..1ad0eee3406 100644 --- a/addons/mail/mail_thread_view.xml +++ b/addons/mail/mail_thread_view.xml @@ -11,7 +11,6 @@ }