From d8a67f02f8de6888ac0ece2437b0b8f9656bbdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 2 Nov 2012 16:24:30 +0100 Subject: [PATCH] [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 --- addons/mail/data/mail_data.xml | 2 +- addons/project/project.py | 50 +++++++++++++++++---------------- addons/project/project_data.xml | 6 ++-- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml index 522cbe8c7a7..9b91c519348 100644 --- a/addons/mail/data/mail_data.xml +++ b/addons/mail/data/mail_data.xml @@ -28,7 +28,7 @@ - comment + Discussions diff --git a/addons/project/project.py b/addons/project/project.py index 59f34fa9599..95348bdede3 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -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): diff --git a/addons/project/project_data.xml b/addons/project/project_data.xml index 560c1c3552a..49c33c8e3a4 100644 --- a/addons/project/project_data.xml +++ b/addons/project/project_data.xml @@ -96,11 +96,11 @@ Task Canceled - project.task + project.project Task Stage Changed - project.task + project.project @@ -112,7 +112,7 @@ project.task - Task canceled + Task Canceled project.task