[FIX] project: fixed auto-follow for task and cleaned code. Also fixed subtype name and related models, as well as comment, now Discussions.

bzr revid: tde@openerp.com-20121102152430-mww1cqcjiluuhtvv
This commit is contained in:
Thibault Delavallée
2012-11-02 16:24:30 +01:00
parent ec906e2f02
commit d8a67f02f8
3 changed files with 30 additions and 28 deletions
+1 -1
View File
@@ -28,7 +28,7 @@
</record>
<record id="mt_comment" model="mail.message.subtype">
<field name="name">comment</field>
<field name="name">Discussions</field>
</record>
</data>
</openerp>
+26 -24
View File
@@ -1129,21 +1129,29 @@ class task(base_stage, osv.osv):
}, context=context)
return True
def _subscribe_project_followers_to_task(self, cr, uid, task_id, context=None):
# task followers are project followers, with matching subtypes
task_record = self.browse(cr, uid, task_id, context=context)
subtype_obj = self.pool.get('mail.message.subtype')
follower_obj = self.pool.get('mail.followers')
if task_record.project_id:
# create mapping
task_subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', False), ('res_model', '=', self._name)], context=context)
task_subtypes = subtype_obj.browse(cr, uid, task_subtype_ids, context=context)
# fetch subscriptions
follower_ids = follower_obj.search(cr, uid, [('res_model', '=', 'project.project'), ('res_id', '=', task_record.project_id.id)], context=context)
# copy followers
for follower in follower_obj.browse(cr, uid, follower_ids, context=context):
if not follower.subtype_ids:
continue
project_subtype_names = [project_subtype.name for project_subtype in follower.subtype_ids]
task_subtype_ids = [task_subtype.id for task_subtype in task_subtypes if task_subtype.name in project_subtype_names]
self.message_subscribe(cr, uid, [task_id], [follower.partner_id.id],
subtype_ids=task_subtype_ids, context=context)
def create(self, cr, uid, vals, context=None):
task_id = super(task, self).create(cr, uid, vals, context=context)
task_record = self.browse(cr, uid, task_id, context=context)
project_obj = self.pool.get("project.project")
subtype_obj = self.pool.get('mail.message.subtype')
subtype_ids = []
if task_record.project_id:
project_subtype = task_record.project_id.message_subtype_data
for key in project_subtype:
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', key)], context=context)
if subtype_ids:
subtype_obj.write(cr,uid, subtype_ids, {'default': project_subtype[key]['default']},context=context)
project_follower_ids = [follower.id for follower in task_record.project_id.message_follower_ids]
self.message_subscribe(cr, uid, [task_id], project_follower_ids, subtype_ids = subtype_ids,
context=context)
self._subscribe_project_followers_to_task(cr, uid, task_id, context=context)
self._store_history(cr, uid, [task_id], context=context)
self.create_send_note(cr, uid, [task_id], context=context)
return task_id
@@ -1153,15 +1161,6 @@ class task(base_stage, osv.osv):
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
project_obj = self.pool.get("project.project")
subtype_obj = self.pool.get('mail.message.subtype')
if vals.get('project_id'):
project_id = project_obj.browse(cr, uid, vals.get('project_id'), context=context)
vals['message_follower_ids'] = [(4, follower.id) for follower in project_id.message_follower_ids]
for key in project_id.message_subtype_data:
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', '=', key)], context=context)
if subtype_ids:
subtype_obj.write(cr,uid, subtype_ids, {'default': project_id.message_subtype_data[key]['default']},context=context)
if vals and not 'kanban_state' in vals and 'stage_id' in vals:
new_stage = vals.get('stage_id')
vals_reset_kstate = dict(vals, kanban_state='normal')
@@ -1171,13 +1170,16 @@ class task(base_stage, osv.osv):
#if new_stage not in stages:
#raise osv.except_osv(_('Warning!'), _('Stage is not defined in the project.'))
write_vals = vals_reset_kstate if t.stage_id != new_stage else vals
super(task,self).write(cr, uid, [t.id], write_vals, context=context)
super(task, self).write(cr, uid, [t.id], write_vals, context=context)
self.stage_set_send_note(cr, uid, [t.id], new_stage, context=context)
result = True
else:
result = super(task,self).write(cr, uid, ids, vals, context=context)
result = super(task, self).write(cr, uid, ids, vals, context=context)
if ('stage_id' in vals) or ('remaining_hours' in vals) or ('user_id' in vals) or ('state' in vals) or ('kanban_state' in vals):
self._store_history(cr, uid, ids, context=context)
if vals.get('project_id'):
for id in ids:
self._subscribe_project_followers_to_task(cr, uid, id, context=context)
return result
def unlink(self, cr, uid, ids, context=None):
+3 -3
View File
@@ -96,11 +96,11 @@
</record>
<record id="mt_project_canceled" model="mail.message.subtype">
<field name="name">Task Canceled</field>
<field name="res_model">project.task</field>
<field name="res_model">project.project</field>
</record>
<record id="mt_project_stage" model="mail.message.subtype">
<field name="name">Task Stage Changed</field>
<field name="res_model">project.task</field>
<field name="res_model">project.project</field>
</record>
<record id="mt_task_new" model="mail.message.subtype">
@@ -112,7 +112,7 @@
<field name="res_model">project.task</field>
</record>
<record id="mt_task_canceled" model="mail.message.subtype">
<field name="name">Task canceled</field>
<field name="name">Task Canceled</field>
<field name="res_model">project.task</field>
</record>
<record id="mt_task_change" model="mail.message.subtype">