summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2012-04-05 23:04:43 +0200
committerThibault Delavallée <tde@openerp.com>2012-04-05 23:04:43 +0200
commit536b08b2f46df8e0a219bcd4fd604c6df39b9d30 (patch)
tree09078ae631aa8dddef2448106be42bf12b4bfc1d
parent230ae5cbdf27f415850a88a7aa8633c546ccc29c (diff)
[ADD] mail.thread: added draft of broadcasting method.
bzr revid: tde@openerp.com-20120405210443-n28i2692zoekmkxr
-rw-r--r--addons/mail/mail_thread.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 8a7e4db30df..b87084cc509 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -19,18 +19,18 @@
#
##############################################################################
-import time
-import tools
import base64
import email
from email.utils import parsedate
-
-import re
import logging
-import xmlrpclib
+from mail_message import decode, to_email
+from operator import itemgetter
from osv import osv, fields
+import re
+import time
+import tools
from tools.translate import _
-from mail_message import decode, to_email
+import xmlrpclib
_logger = logging.getLogger(__name__)
@@ -686,6 +686,26 @@ class mail_thread(osv.osv):
# Note specific
#------------------------------------------------------
+ def message_broadcast(self, cr, uid, ids, subject=None, body=None, parent_id=False, type='notification', subtype='html', context=None):
+ if context is None:
+ context = {}
+ notification_obj = self.pool.get('mail.notification')
+ # write message
+ msg_ids = self.message_append_note(cr, uid, ids, subject=subject, body=body, parent_id=parent_id, type=type, subtype=subtype, context=context)
+ # get already existing notigications
+ notification_ids = notification_obj.search(cr, uid, [('message_id', 'in', msg_ids)], context=context)
+ already_pushed_user_ids = map(itemgetter('user_id'), notification_obj.read(cr, uid, notification_ids, context=context))
+ # get base.group_user group
+ res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_user') or False
+ group_id = res and res[1] or False
+ if not group_id: return True
+ group = self.pool.get('res.groups').browse(cr, uid, [group_id], context=context)[0]
+ for user in group.users:
+ if user.id in already_pushed_user_ids: continue
+ for msg_id in msg_ids:
+ notification_obj.create(cr, uid, {'user_id': user.id, 'message_id': msg_id}, context=context)
+ return True
+
def log(self, cr, uid, id, message, secondary=False, context=None):
_logger.warning("log() is deprecated. Please use OpenChatter notification system instead of the res.log mechanism.")
self.message_append_note(cr, uid, [id], 'res.log', message, context=context)