diff --git a/addons/project/models/project_task.py b/addons/project/models/project_task.py index 01360b31fdb..657a4158dca 100644 --- a/addons/project/models/project_task.py +++ b/addons/project/models/project_task.py @@ -190,7 +190,7 @@ class Task(models.Model): # In the domain of displayed_image_id, we couln't use attachment_ids because a one2many is represented as a list of commands so we used res_model & res_id displayed_image_id = fields.Many2one('ir.attachment', domain="[('res_model', '=', 'project.task'), ('res_id', '=', id), ('mimetype', 'ilike', 'image')]", string='Cover Image') - parent_id = fields.Many2one('project.task', string='Parent Task', index=True, domain="['!', ('id', 'child_of', id)]") + parent_id = fields.Many2one('project.task', string='Parent Task', index=True, domain="['!', ('id', 'child_of', id)]", tracking=True) child_ids = fields.One2many('project.task', 'parent_id', string="Sub-tasks", domain="[('recurring_task', '=', False)]") subtask_count = fields.Integer("Sub-task Count", compute='_compute_subtask_count') closed_subtask_count = fields.Integer("Closed Sub-tasks Count", compute='_compute_subtask_count') @@ -1564,6 +1564,26 @@ class Task(models.Model): self.recurrence_id.task_ids.recurring_task = False self.recurrence_id.unlink() + def action_convert_to_subtask(self): + self.ensure_one() + if self.project_id: + return { + 'name': _('Convert to Task/Sub-Task'), + 'type': 'ir.actions.act_window', + 'res_model': 'project.task', + 'res_id': self.id, + 'views': [(self.env.ref('project.project_task_convert_to_subtask_view_form', False).id, 'form')], + 'target': 'new', + } + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'type': 'danger', + 'message': _('Private tasks cannot be converted into sub-tasks. Please set a project for the task to gain access to this feature.'), + } + } + # --------------------------------------------------- # Rating business # --------------------------------------------------- diff --git a/addons/project/views/project_task_views.xml b/addons/project/views/project_task_views.xml index b61e3054db6..62131f10958 100644 --- a/addons/project/views/project_task_views.xml +++ b/addons/project/views/project_task_views.xml @@ -291,7 +291,20 @@ - + + + + + + Sub-tasks + + + + + + Closed + + @@ -506,6 +519,27 @@ + + project.task.convert.to.subtask.form + project.task + + + + To transform a task into a sub-task, select a parent task. Alternatively, leave the parent task field blank to convert a sub-task into a standalone task. + + + + + + + + + + + project.task.kanban project.task @@ -981,6 +1015,17 @@ + + Convert to Task/Sub-Task + + + form + code + + action = record.action_convert_to_subtask() + + + Tasks project.task