[IMP] mail_thread: cleaned message_get_subscribers and related methods; propagated change so that project_issue, mrp, crm_lead, project, project_task, hr_recruitment and hr_holidays now cleanly override message_get_subscribers.
bzr revid: tde@openerp.com-20120605122221-nvxfxfcx5o82vkvx
This commit is contained in:
parent
b3295905f7
commit
6aa0ca7a7e
|
@ -862,13 +862,13 @@ class crm_lead(base_stage, osv.osv):
|
|||
# ----------------------------------------
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context)
|
||||
# add salesman to the subscribers
|
||||
""" Override to add the salesman. """
|
||||
user_ids = super(crm_lead, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.user_id:
|
||||
sub_ids.append(obj.user_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
return user_ids
|
||||
|
||||
def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
|
||||
""" Override of the (void) default notification method. """
|
||||
stage_name = self.pool.get('crm.case.stage').name_get(cr, uid, [stage_id], context=context)[0][1]
|
||||
|
|
|
@ -370,14 +370,16 @@ class hr_holidays(osv.osv):
|
|||
hr_manager_group = self.pool.get('res.groups').read(cr, uid, [obj_id], ['users'], context=context)[0]
|
||||
result[obj.id] = hr_manager_group['users']
|
||||
return result
|
||||
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
# add the employee and its manager if specified to the subscribed users
|
||||
""" Override to add employee and its manager. """
|
||||
user_ids = super(project_issue, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.employee_id.parent_id:
|
||||
sub_ids.append(obj.employee_id.parent_id.user_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
if obj.employee_id.parent_id and not obj.employee_id.parent_id.user_id.id in user_ids:
|
||||
user_ids.append(obj.employee_id.parent_id.user_id.id)
|
||||
return user_ids
|
||||
|
||||
def create_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
|
|
|
@ -497,13 +497,14 @@ class hr_applicant(base_stage, osv.Model):
|
|||
# -------------------------------------------------------
|
||||
# OpenChatter methods and notifications
|
||||
# -------------------------------------------------------
|
||||
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
""" Override to add responsible user. """
|
||||
user_ids = super(project_issue, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.user_id:
|
||||
sub_ids.append(obj.user_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
return user_ids
|
||||
|
||||
def get_needaction_user_ids(self, cr, uid, ids, context=None):
|
||||
result = dict.fromkeys(ids, [])
|
||||
|
|
|
@ -751,51 +751,76 @@ class mail_thread(osv.Model):
|
|||
# Subscription mechanism
|
||||
#------------------------------------------------------
|
||||
|
||||
def message_get_subscribers_ids(self, cr, uid, ids, context=None):
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
""" Returns the current document followers. Basically this method
|
||||
checks in mail.subscription for entries with matching res_model,
|
||||
res_id.
|
||||
|
||||
:param get_ids: if set to True, return the ids of users; if set
|
||||
to False, returns the result of a read in res.users
|
||||
"""
|
||||
subscr_obj = self.pool.get('mail.subscription')
|
||||
subscr_ids = subscr_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
subs = subscr_obj.read(cr, uid, subscr_ids, context=context)
|
||||
return [sub['user_id'][0] for sub in subs]
|
||||
return [sub['user_id'][0] for sub in subscr_obj.read(cr, uid, subscr_ids, ['user_id'], context=context)]
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
user_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context)
|
||||
users = self.pool.get('res.users').read(cr, uid, user_ids, fields=['id', 'name', 'avatar'], context=context)
|
||||
return users
|
||||
def message_read_subscribers(self, cr, uid, ids, fields=['id', 'name', 'avatar'], context=None):
|
||||
""" Returns the current document followers as a read result. Used
|
||||
mainly for Chatter having only one method to call to have
|
||||
details about users.
|
||||
"""
|
||||
user_ids = self.message_get_subscribers(cr, uid, ids, context=context)
|
||||
return self.pool.get('res.users').read(cr, uid, user_ids, fields=fields, context=context)
|
||||
|
||||
def message_is_subscriber(self, cr, uid, ids, user_id = None, context=None):
|
||||
users = self.message_get_subscribers(cr, uid, ids, context=context)
|
||||
""" Check if uid or user_id (if set) is a subscriber to the current
|
||||
document.
|
||||
|
||||
:param user_id: if set, check is done on user_id; if not set
|
||||
check is done on uid
|
||||
"""
|
||||
sub_user_id = uid if user_id is None else user_id
|
||||
if sub_user_id in [user['id'] for user in users]:
|
||||
if sub_user_id in self.message_get_subscribers(cr, uid, ids, context=context):
|
||||
return True
|
||||
return False
|
||||
|
||||
def message_subscribe(self, cr, uid, ids, user_ids = None, context=None):
|
||||
""" Subscribe the user (or user_ids) to the current document.
|
||||
|
||||
:param user_ids: a list of user_ids; if not set, subscribe
|
||||
uid instead
|
||||
"""
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
to_subscribe_uids = [uid] if user_ids is None else user_ids
|
||||
create_ids = []
|
||||
for id in ids:
|
||||
already_subscribed_user_ids = self.message_get_subscribers(cr, uid, [id], context=context)
|
||||
for user_id in to_subscribe_uids:
|
||||
if self.message_is_subscriber(cr, uid, [id], user_id=user_id, context=context): continue
|
||||
if user_id in already_subscribed_user_ids: continue
|
||||
create_ids.append(subscription_obj.create(cr, uid, {'res_model': self._name, 'res_id': id, 'user_id': user_id}, context=context))
|
||||
return create_ids
|
||||
|
||||
def message_unsubscribe(self, cr, uid, ids, user_ids = None, context=None):
|
||||
if not user_ids and not uid in self.message_get_subscribers_ids(cr, uid, ids, context=context):
|
||||
""" Unsubscribe the user (or user_ids) from the current document.
|
||||
|
||||
:param user_ids: a list of user_ids; if not set, subscribe
|
||||
uid instead
|
||||
"""
|
||||
# Trying to unsubscribe somebody not in subscribers: returns False
|
||||
# if special management is needed; allows to know that an automatically
|
||||
# subscribed user tries to unsubscribe and allows to warn him
|
||||
if not user_ids and not uid in self.message_get_subscribers(cr, uid, ids, context=context):
|
||||
return False
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
to_unsubscribe_uids = [uid] if user_ids is None else user_ids
|
||||
to_delete_sub_ids = subscription_obj.search(cr, uid,
|
||||
['&', '&', ('res_model', '=', self._name), ('res_id', 'in', ids), ('user_id', 'in', to_unsubscribe_uids)], context=context)
|
||||
subscription_obj.unlink(cr, uid, to_delete_sub_ids, context=context)
|
||||
return True
|
||||
return subscription_obj.unlink(cr, uid, to_delete_sub_ids, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Notification API
|
||||
#------------------------------------------------------
|
||||
|
||||
def message_remove_pushed_notifications(self, cr, uid, ids, msg_ids, remove_childs=True, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
notif_obj = self.pool.get('mail.notification')
|
||||
msg_obj = self.pool.get('mail.message')
|
||||
if remove_childs:
|
||||
|
|
|
@ -529,7 +529,7 @@ openerp.mail = function(session) {
|
|||
},
|
||||
|
||||
fetch_subscribers: function () {
|
||||
return this.ds.call('message_get_subscribers', [[this.view.datarecord.id]]).then(this.proxy('display_subscribers'));
|
||||
return this.ds.call('message_read_subscribers', [[this.view.datarecord.id]]).then(this.proxy('display_subscribers'));
|
||||
},
|
||||
|
||||
display_subscribers: function (records) {
|
||||
|
|
|
@ -1042,11 +1042,12 @@ class mrp_production(osv.osv):
|
|||
return result
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
""" Override to add responsible user. """
|
||||
user_ids = super(mrp_production, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.user_id:
|
||||
sub_ids.append(obj.user_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
return user_ids
|
||||
|
||||
def create_send_note(self, cr, uid, ids, context=None):
|
||||
self.message_append_note(cr, uid, ids, body=_("Manufacturing order has been <b>created</b>."), context=context)
|
||||
|
|
|
@ -475,11 +475,12 @@ def Project():
|
|||
return result
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
""" Override to add responsible user. """
|
||||
user_ids = super(project, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.user_id:
|
||||
sub_ids.append(obj.user_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
return user_ids
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
obj_id = super(project, self).create(cr, uid, vals, context=context)
|
||||
|
@ -1152,13 +1153,14 @@ class task(base_stage, osv.osv):
|
|||
return result
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
""" Override to add responsible user and project manager. """
|
||||
user_ids = super(project_task, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.user_id:
|
||||
sub_ids.append(obj.user_id.id)
|
||||
if obj.manager_id:
|
||||
sub_ids.append(obj.manager_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
if obj.manager_id and not obj.manager_id.id in user_ids:
|
||||
user_ids.append(obj.manager_id.id)
|
||||
return user_ids
|
||||
|
||||
def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
|
||||
""" Override of the (void) default notification method. """
|
||||
|
|
|
@ -530,11 +530,12 @@ class project_issue(base_stage, osv.osv):
|
|||
return result
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
""" Override to add responsible user. """
|
||||
user_ids = super(project_issue, self).message_get_subscribers(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.user_id:
|
||||
sub_ids.append(obj.user_id.id)
|
||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||
if obj.user_id and not obj.user_id.id in user_ids:
|
||||
user_ids.append(obj.user_id.id)
|
||||
return user_ids
|
||||
|
||||
def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
|
||||
""" Override of the (void) default notification method. """
|
||||
|
|
Loading…
Reference in New Issue