From f34f6ee3b627f3656cc6fe97fe8504beba55adf9 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 15 Nov 2019 12:00:52 +0000 Subject: [PATCH] [IMP] project: Allow multi levels on sub-tasks Purpose ======= Currently, it is only possible to have 1 level of sub-tasks per task. The user may want several levels of granurality. Specifications ============== Allow having multi levels of sub-tasks - Move the parent_id field out of the debug mode and display it above the Deadline field - Remove the 'parent task' stat button - Add the parent_id field to the project.task optional list view - Display the sub-tasks stat button on sub-tasks - The 'sub-tasks' stat button should only count/display tasks from the first level of sub-tasks - The name of the sub-task should be parent task: sub task level 1: sub task level 2: sub task level 3... - The sub-task should be created in the sub-task project set on the parent task's project - The subtask_planned_hours and the subtask_effective_hours fields should take into account the planned hours of all sub-level tasks TaskID: 2107078 --- addons/project/models/project.py | 26 +++++++++--------------- addons/project/views/project_views.xml | 28 ++++++++++++-------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 4a5f3b0c5d2..cf0679faf62 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -588,15 +588,12 @@ class Task(models.Model): @api.depends('child_ids.planned_hours') def _compute_subtask_planned_hours(self): for task in self: - task.subtask_planned_hours = sum(task.child_ids.mapped('planned_hours')) + task.subtask_planned_hours = sum(child_task.planned_hours + child_task.subtask_planned_hours for child_task in task.child_ids) @api.depends('child_ids') def _compute_subtask_count(self): - """ Note: since we accept only one level subtask, we can use a read_group here """ - task_data = self.env['project.task'].read_group([('parent_id', 'in', self.ids)], ['parent_id'], ['parent_id']) - mapping = dict((data['parent_id'][0], data['parent_id_count']) for data in task_data) for task in self: - task.subtask_count = mapping.get(task.id, 0) + task.subtask_count = len(self._get_all_subtasks()) @api.onchange('project_id') def _onchange_project(self): @@ -882,21 +879,17 @@ class Task(models.Model): def action_assign_to_me(self): self.write({'user_id': self.env.user.id}) - def action_open_parent_task(self): - return { - 'name': _('Parent Task'), - 'view_mode': 'form', - 'res_model': 'project.task', - 'res_id': self.parent_id.id, - 'type': 'ir.actions.act_window', - 'context': dict(self._context, create=False) - } + def _get_all_subtasks(self): + children = self.mapped('child_ids') + if not children: + return self.env['project.task'] + return children + children._get_all_subtasks() def action_subtask(self): action = self.env.ref('project.project_task_action_sub_task').read()[0] - # only display subtasks of current task - action['domain'] = [('id', 'child_of', self.id), ('id', '!=', self.id)] + # display all subtasks of current task + action['domain'] = [('id', 'in', self._get_all_subtasks().ids)] # update context, with all default values as 'quick_create' does not contains all field in its view if self._context.get('default_project_id'): @@ -908,7 +901,6 @@ class Task(models.Model): 'default_name': self.env.context.get('name', self.name) + ':', 'default_parent_id': self.id, # will give default subtask field in `default_get` 'default_company_id': default_project.company_id.id if default_project else self.env.company.id, - 'search_default_parent_id': self.id, }) action['context'] = ctx diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml index 8b99bcd4273..66d5c651be4 100644 --- a/addons/project/views/project_views.xml +++ b/addons/project/views/project_views.xml @@ -76,7 +76,7 @@ Sub-tasks project.task - kanban,tree,form,calendar,pivot,graph,activity + tree,kanban,form,calendar,pivot,graph,activity @@ -451,9 +451,8 @@
-