[IMP] mail.group: added overrider of message_load method, allowing to get messages of followed models in Chatter widget.

bzr revid: tde@openerp.com-20120503080925-bj3777jkdn5gebvp
This commit is contained in:
Thibault Delavallée 2012-05-03 10:09:25 +02:00
parent ffe8871a71
commit 2fe3e0508d
1 changed files with 50 additions and 14 deletions

View File

@ -49,12 +49,6 @@ class mail_group(osv.osv):
_name = 'mail.group'
_inherit = ['mail.thread']
def action_group_join(self, cr, uid, ids, context={}):
return self.message_subscribe(cr, uid, ids, context=context);
def action_group_leave(self, cr, uid, ids, context={}):
return self.message_unsubscribe(cr, uid, ids, context=context);
def onchange_photo(self, cr, uid, ids, value, context=None):
if not value:
return {'value': {'avatar_big': value, 'avatar': value} }
@ -118,19 +112,28 @@ class mail_group(osv.osv):
'responsible_id': fields.many2one('res.users', string='Responsible',
ondelete='set null', required=True, select=1,
help="Responsible of the group that has all rights on the record."),
'public': fields.boolean('Public', help='This group is visible by non members. Invisible groups can add members through the invite button.'),
'models': fields.many2many('ir.model', rel='mail_group_models_rel', id1='mail_group_id', id2='model_id',
'public': fields.boolean('Public', help='This group is visible by non members. \
Invisible groups can add members through the invite button.'),
'models': fields.many2many('ir.model', rel='mail_group_models_rel',
id1='mail_group_id', id2='model_id',
string='Linked models', help='Linked models'),
'photo_big': fields.binary('Full-size photo', help='Field holding the full-sized PIL-supported and base64 encoded version of the group image. The photo field is used as an interface for this field.'),
'photo_big': fields.binary('Full-size photo', help='Field holding \
the full-sized PIL-supported and base64 encoded \
version of the group image. The photo field is \
used as an interface for this field.'),
'photo': fields.function(_get_photo, fnct_inv=_set_photo, string='Photo', type="binary",
store = {
'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['photo_big'], 10),
}, help='Field holding the automatically resized (128x128) PIL-supported and base64 encoded version of the group image.'),
'member_ids': fields.function(get_member_ids, fnct_search=search_member_ids, type='many2many',
relation='res.users', string='Group members', multi='get_member_ids'),
'member_count': fields.function(get_member_ids, type='integer', string='Member count', multi='get_member_ids'),
'is_subscriber': fields.function(get_member_ids, type='boolean', string='Joined', multi='get_member_ids'),
'last_month_msg_nbr': fields.function(get_last_month_msg_nbr, type='integer', string='Messages count for last month'),
'member_ids': fields.function(get_member_ids, fnct_search=search_member_ids,
type='many2many', relation='res.users',
string='Group members', multi='get_member_ids'),
'member_count': fields.function(get_member_ids, type='integer',
string='Member count', multi='get_member_ids'),
'is_subscriber': fields.function(get_member_ids, type='boolean',
string='Joined', multi='get_member_ids'),
'last_month_msg_nbr': fields.function(get_last_month_msg_nbr, type='integer',
string='Messages count for last month'),
}
_defaults = {
@ -138,3 +141,36 @@ class mail_group(osv.osv):
'responsible_id': (lambda s, cr, uid, ctx: uid),
'photo': _get_default_photo,
}
def message_load(self, cr, uid, ids, limit=100, offset=0, domain=[], ascent=False, root_ids=[], context=None):
""" Override OpenChatter method.
if models attribute is set: search all messages from that model
else: as usual
:param domain: domain to add to the search; especially child_of
is interesting when dealing with threaded display
:param ascent: performs an ascended search; will add to fetched msgs
all their parents until root_ids
:param root_ids: for ascent search
:param root_ids: root_ids when performing an ascended search
"""
search_domain = []
for group in self.browse(cr, uid, ids, context=context):
# call super to have default message ids
message_obj = self.pool.get('mail.message')
group_msgs = super(mail_group, self).message_load(cr, uid, ids, limit, offset, domain, ascent, root_ids, context)
msg_ids = map(itemgetter('id'), group_msgs)
search_domain = ['|', '&', ('model', '=', self._name), ('id', 'in', ids)]
# add message ids linked to group models
model_list = []
for model in group.models:
model_list.append(model.model)
search_domain.append(('model', 'in', model_list))
msg_ids += message_obj.search(cr, uid, search_domain, limit=limit, offset=offset, context=context)
return message_obj.read(cr, uid, msg_ids, context=context)
def action_group_join(self, cr, uid, ids, context=None):
return self.message_subscribe(cr, uid, ids, context=context)
def action_group_leave(self, cr, uid, ids, context=None):
return self.message_unsubscribe(cr, uid, ids, context=context)