[IMP] mail: refactored mechanism for auto subscription, based on a parent. Mapping of subtypes is done using parent_id and parent_field on child subtypes. For example, project subtypes are linked to task subtypes, using parent_id and parent_field project_id, to browse task.project_id.
bzr revid: tde@openerp.com-20121218153457-uh50bjedvxaawdqj
This commit is contained in:
@@ -39,6 +39,10 @@ class mail_message_subtype(osv.osv):
|
||||
'description': fields.text('Description', translate=True,
|
||||
help='Description that will be added in the message posted for this '\
|
||||
'subtype. If void, no message will be added.'),
|
||||
'parent_id': fields.many2one('mail.message.subtype', string='Parent',
|
||||
ondelete='set null'),
|
||||
'parent_field': fields.char('Parent field',
|
||||
help='Field used to find the parent model'),
|
||||
'res_model': fields.char('Model',
|
||||
help="Model the subtype applies to. If False, this subtype exists for all models."),
|
||||
'default': fields.boolean('Default',
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
<field name="res_model"/>
|
||||
<field name="default"/>
|
||||
<field name="description"/>
|
||||
<field name="parent_id"/>
|
||||
<field name="parent_field"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
||||
@@ -239,6 +239,7 @@ class mail_thread(osv.AbstractModel):
|
||||
# subscribe uid unless asked not to
|
||||
if not context.get('mail_nosubscribe'):
|
||||
self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context)
|
||||
self.message_subscribe_from_parent(cr, uid, [thread_id], context=context)
|
||||
|
||||
# automatic logging
|
||||
# self.message_post(cr, uid, thread_id, body='Document <b>created</b>.', context=context)
|
||||
@@ -953,6 +954,31 @@ class mail_thread(osv.AbstractModel):
|
||||
self.check_access_rights(cr, uid, 'read')
|
||||
return self.write(cr, SUPERUSER_ID, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context)
|
||||
|
||||
def message_subscribe_from_parent(self, cr, uid, ids, context=None):
|
||||
|
||||
subtype_obj = self.pool.get('mail.message.subtype')
|
||||
follower_obj = self.pool.get('mail.followers')
|
||||
|
||||
# fetch record subtypes
|
||||
subtype_ids = subtype_obj.search(cr, uid, ['|', ('parent_id.res_model', '=', False), ('parent_id.res_model', '=', self._name)], context=context)
|
||||
if not subtype_ids:
|
||||
return
|
||||
subtypes = subtype_obj.browse(cr, uid, subtype_ids, context=context)
|
||||
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
new_followers = dict()
|
||||
for subtype in subtypes:
|
||||
if subtype.parent_field and subtype.parent_id:
|
||||
if subtype.parent_field in self._columns and getattr(record, subtype.parent_field):
|
||||
parent_res_id = getattr(record, subtype.parent_field).id
|
||||
parent_model = subtype.res_model
|
||||
follower_ids = follower_obj.search(cr, SUPERUSER_ID, [('res_model', '=', parent_model), ('res_id', '=', parent_res_id), ('subtype_ids', 'in', [subtype.id])], context=context)
|
||||
for follower in follower_obj.browse(cr, SUPERUSER_ID, follower_ids, context=context):
|
||||
new_followers.setdefault(follower.partner_id.id, set()).add(subtype.parent_id.id)
|
||||
|
||||
for pid, subtypes in new_followers.items():
|
||||
self.message_subscribe(cr, uid, [record.id], [pid], list(subtypes), context=context)
|
||||
|
||||
def _subscribe_followers_subtype(self, cr, uid, ids, res_id, model, context=None):
|
||||
""" TDE note: not the best way to do this, we could override _get_followers
|
||||
of task, and perform a better mapping of subtypes than a mapping
|
||||
|
||||
@@ -594,9 +594,8 @@ class test_mail(TestMailBase):
|
||||
def _strip_string_spaces(body):
|
||||
return body.replace(' ', '').replace('\n', '')
|
||||
|
||||
cr, uid = self.cr, self.uid
|
||||
|
||||
# Data: subscribe Raoul to Pigs, because he will change the public attribute and may loose access to the record
|
||||
cr, uid = self.cr, self.uid
|
||||
self.mail_group.message_subscribe_users(cr, uid, [self.group_pigs_id], [self.user_raoul_id])
|
||||
|
||||
# Data: res.users.group, to test group_public_id automatic logging
|
||||
|
||||
Reference in New Issue
Block a user