diff --git a/addons/project/project.py b/addons/project/project.py index 95348bdede3..b358616508f 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -1151,7 +1151,9 @@ class task(base_stage, osv.osv): def create(self, cr, uid, vals, context=None): task_id = super(task, self).create(cr, uid, vals, context=context) + # subscribe project followers to the task 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 @@ -1177,6 +1179,8 @@ class task(base_stage, osv.osv): 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) + + # subscribe new project followers to the task if vals.get('project_id'): for id in ids: self._subscribe_project_followers_to_task(cr, uid, id, context=context) diff --git a/addons/project/project_data.xml b/addons/project/project_data.xml index 49c33c8e3a4..4f467c89a29 100644 --- a/addons/project/project_data.xml +++ b/addons/project/project_data.xml @@ -86,37 +86,37 @@ - New Task + New project.project - Task Closed + Closed project.project - Task Canceled + Canceled project.project - Task Stage Changed + Stage Changed project.project - New Task + New project.task - Task Closed + Closed project.task - Task Canceled + Canceled project.task - Task Stage Changed + Stage Changed project.task diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index 88013ad225c..720e6e8c2dd 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -359,31 +359,44 @@ class project_issue(base_stage, osv.osv): return super(project_issue, self).copy(cr, uid, id, default=default, context=context) + def _subscribe_project_followers_to_issue(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 write(self, cr, uid, ids, vals, context=None): #Update last action date every time the user change the stage, the state or send a new email logged_fields = ['stage_id', 'state', 'message_ids'] - subtype_obj = self.pool.get('mail.message.subtype') - name = False if any([field in vals for field in logged_fields]): vals['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S') + + # subscribe new project followers to the issue if vals.get('project_id'): - project_id = self.pool.get('project.project').browse(cr, uid, vals.get('project_id'), context=context) - for key in project_id.message_subtype_data: - if key == 'New Task' and project_id.message_subtype_data[key]['default'] == True: - name = 'created' - if key == 'Task Closed' and project_id.message_subtype_data[key]['default'] == True: - name = 'closed' - subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', name)], context=context) - subtype_obj.write(cr,uid, subtype_ids, {'default': project_id.message_subtype_data[key]['default']},context=context) - vals['message_follower_ids'] = [(4, follower.id) for follower in project_id.message_follower_ids] + for id in ids: + self._subscribe_project_followers_to_issue(cr, uid, id, context=context) return super(project_issue, self).write(cr, uid, ids, vals, context) def onchange_task_id(self, cr, uid, ids, task_id, context=None): if not task_id: - return {'value':{}} + return {'value': {}} task = self.pool.get('project.task').browse(cr, uid, task_id, context=context) - return {'value':{'user_id': task.user_id.id,}} + return {'value': {'user_id': task.user_id.id, }} def case_reset(self, cr, uid, ids, context=None): """Resets case as draft @@ -393,21 +406,12 @@ class project_issue(base_stage, osv.osv): return res def create(self, cr, uid, vals, context=None): - subtype_obj = self.pool.get('mail.message.subtype') obj_id = super(project_issue, self).create(cr, uid, vals, context=context) - project_id = self.browse(cr, uid, obj_id, context=context).project_id - name = False - if project_id: - for key in project_id.message_subtype_data: - if key == 'New Task' and project_id.message_subtype_data[key]['default'] == True: - name = 'created' - if key == 'Task Closed' and project_id.message_subtype_data[key]['default'] == True: - name = 'closed' - subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', name)], context=context) - subtype_obj.write(cr,uid, subtype_ids, {'default': project_id.message_subtype_data[key]['default']},context=context) - followers = [follower.id for follower in project_id.message_follower_ids] - self.message_subscribe(cr, uid, [obj_id], followers, subtype_ids= subtype_ids, context=context) + + # subscribe project follower to the issue + self._subscribe_project_followers_to_issue(cr, uid, obj_id, context=context) self.create_send_note(cr, uid, [obj_id], context=context) + return obj_id # ------------------------------------------------------- diff --git a/addons/project_issue/project_issue_data.xml b/addons/project_issue/project_issue_data.xml index edd44e52dd2..72f824715a8 100644 --- a/addons/project_issue/project_issue_data.xml +++ b/addons/project_issue/project_issue_data.xml @@ -44,17 +44,19 @@ Access all issues from the top Project menu, and access the issues of a specific - created + New project.issue - - - - stage change - project.issue - - closed + Closed + project.issue + + + Canceled + project.issue + + + Stage Changed project.issue