From: Thibault Delavallée Date: Thu, 2 Feb 2012 11:26:57 +0000 (+0100) Subject: [IMP] Added push of messages when creating one. Fixed bugs in mail_thread subscriptio... X-Git-Tag: 7.0-server~3709^2~251 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=109647a109de0f0c45329570ff1b5e863359717e;p=odoo%2Fodoo.git [IMP] Added push of messages when creating one. Fixed bugs in mail_thread subscription mechanism. Added list views for subscriptions and notifications. Subscription is now unread by default. bzr revid: tde@openerp.com-20120202112657-zj406ck98n06imo9 --- diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 877ffd9..dfd2fe0 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -71,8 +71,8 @@ class mail_message_common(osv.osv_memory): _rec_name = 'subject' _columns = { 'subject': fields.char('Subject', size=512, required=True), - 'model': fields.char('Related Document model', size=128, select=1), # was rfeadonly - 'res_id': fields.integer('Related Document ID', select=1), # was rfeadonly + 'model': fields.char('Related Document model', size=128, select=1), # was readonly + 'res_id': fields.integer('Related Document ID', select=1), # was readonly 'date': fields.datetime('Date'), 'email_from': fields.char('From', size=128, help='Message sender, taken from user preferences. If empty, this is not a mail but a message.'), 'email_to': fields.char('To', size=256, help='Message recipients'), @@ -191,11 +191,23 @@ class mail_message(osv.osv): } #------------------------------------------------------ - # Note specific api + # Generic api #------------------------------------------------------ def create(self, cr, uid, vals, context=None): - return super(mail_message, self).create(cr, uid, vals, context) + msg_id = super(mail_message, self).create(cr, uid, vals, context) + # push the message to suscribed users + subscription_obj = self.pool.get('mail.subscription') + notification_obj = self.pool.get('mail.notification') + sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', vals['model']), ('user_id', '=', uid)], context=context) + subs = subscription_obj.browse(cr, uid, sub_ids, context=context) + for sub in subs: + notification_obj.create(cr, uid, {'user_id': sub.user_id, 'message_id': msg_id}, context=context) + return msg_id + + #------------------------------------------------------ + # Note specific api + #------------------------------------------------------ def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): if not context or not context.has_key('filter_search'): diff --git a/addons/mail/mail_subscription.py b/addons/mail/mail_subscription.py index f250ddc..89750c4 100644 --- a/addons/mail/mail_subscription.py +++ b/addons/mail/mail_subscription.py @@ -30,7 +30,7 @@ class mail_subscription(osv.osv): A subscription can be of following: - res_model: model of the followed objects - res_id: ID of resource OR - - res_domain: a domain filtering followed objects + - res_domain: a domain filtering followed objects - currently removed """ _name = 'mail.subscription' @@ -38,7 +38,7 @@ class mail_subscription(osv.osv): _columns = { 'res_model': fields.char('Related Document model', size=128, select=1), 'res_id': fields.integer('Related Document ID', select=1), - 'res_domain': fields.char('res_domain', size=256), + #'res_domain': fields.char('res_domain', size=256), 'user_id': fields.integer('Related User ID', select=1), } @@ -63,6 +63,7 @@ class mail_notification(osv.osv): } _defaults = { + 'read': False, } mail_notification() diff --git a/addons/mail/mail_subscription_view.xml b/addons/mail/mail_subscription_view.xml index 75f0408..2850cd2 100644 --- a/addons/mail/mail_subscription_view.xml +++ b/addons/mail/mail_subscription_view.xml @@ -2,6 +2,42 @@ + + + + mail.subscription.tree + mail.subscription + tree + 10 + + + + + + + + + + + + + mail.notification.tree + mail.notification + tree + 10 + + + + + + + + + Subscriptions mail.subscription diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 8d5a05f..e9df98e 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -504,7 +504,7 @@ class mail_thread(osv.osv): def message_get_subscribers(self, cr, uid, ids, context=None): subscription_obj = self.pool.get('mail.subscription') for id in ids: - sub_ids = subscription_obj.search(cr, uid, ['res_model': self._name, 'res_id': id], context=context) + sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', '=', id)], context=context) subs = subscription_obj.browse(cr, uid, sub_ids, context=context) return subs @@ -520,7 +520,7 @@ class mail_thread(osv.osv): subscriber_id = uid # TODO sub_ids = [] for id in ids: - sub_ids += subscription_obj.search(cr, uid, ['res_model': self._name, 'res_id': id, 'user_id': subscriber_id], context=context) + sub_ids += subscription_obj.search(cr, uid, ['&', '&', ('res_model', '=', self._name), ('res_id', '=', id), ('user_id', '=', subscriber_id)], context=context) subscription_obj.unlink(cr, uid, ids, context=context) return True