[IMP] project: add task dependencies feature in project.task model

This commit adds two new fields in the project.task model.
The first one called 'allow_task_dependencies' is a related field to the
one project.project model. The other field called 'depend_on_ids' is a
Many2many field will contain the tasks which the current task depend on.

In the form view of project.task model, these fields are added.

task-2387984

closes #66740
This commit is contained in:
Xavier BOL (xbo)
2021-03-12 14:15:36 +01:00
parent 70d7f31d58
commit d2dadbcc3b
7 changed files with 89 additions and 1 deletions
@@ -196,6 +196,15 @@
</group>
</page>
</xpath>
<xpath expr="//field[@name='depend_on_ids']/tree//field[@name='company_id']" position="after">
<field name="allow_subtasks" invisible="1" />
<field name="planned_hours" widget="timesheet_uom_no_toggle" sum="Initially Planned Hours" optional="hide"/>
<field name="effective_hours" widget="timesheet_uom" sum="Effective Hours" optional="hide"/>
<field name="remaining_hours" widget="timesheet_uom" sum="Remaining Hours" optional="hide" decoration-danger="progress &gt;= 100" decoration-warning="progress &gt;= 80 and progress &lt; 100"/>
<field name="subtask_effective_hours" widget="timesheet_uom" attrs="{'invisible' : [('allow_subtasks', '=', False)]}" optional="hide"/>
<field name="total_hours_spent" widget="timesheet_uom" attrs="{'invisible' : [('allow_subtasks', '=', False)]}" optional="hide"/>
<field name="progress" widget="progressbar" optional="hide" groups="hr_timesheet.group_hr_timesheet_user"/>
</xpath>
</field>
</record>
+15 -1
View File
@@ -650,6 +650,10 @@ class Task(models.Model):
# customer portal: include comment and incoming emails in communication history
website_message_ids = fields.One2many(domain=lambda self: [('model', '=', self._name), ('message_type', 'in', ['email', 'comment'])])
# Task Dependencies fields
allow_task_dependencies = fields.Boolean(related='project_id.allow_task_dependencies')
depend_on_ids = fields.Many2many('project.task', relation="task_dependencies_rel", column1="task_id", column2="depends_on_id", string="Blocked By")
# recurrence fields
allow_recurring_tasks = fields.Boolean(related='project_id.allow_recurring_tasks')
recurring_task = fields.Boolean(string="Recurrent")
@@ -1172,7 +1176,7 @@ class Task(models.Model):
if task.project_id.partner_id:
task.partner_id = task.project_id.partner_id
else:
task.partner_id = task.project_id.partner_id or task.parent_id.partner_id
task.partner_id = task.project_id.partner_id or task.parent_id.partner_id
@api.depends('partner_id.email', 'parent_id.email_from')
def _compute_email_from(self):
@@ -1393,6 +1397,16 @@ class Task(models.Model):
# Actions
# ------------
def action_open_task_form(self):
""" Opens the form view of the task """
return {
'view_mode': 'form',
'res_model': 'project.task',
'res_id': self.id,
'type': 'ir.actions.act_window',
'context': dict(self._context, create=False)
}
def action_recurring_tasks(self):
return {
'name': 'Tasks in Recurrence',
@@ -0,0 +1,3 @@
.o_form_project_tasks div.o_field_many2many[name=depend_on_ids] tr.o_selected_row td.o_list_button {
background-color: $table-border-color !important;
}
+1
View File
@@ -7,3 +7,4 @@ from . import test_project_flow
from . import test_project_recurrence
from . import test_project_ui
from . import test_multicompany
from . import test_task_dependencies
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
from odoo.fields import Command
from odoo.exceptions import ValidationError
from odoo.tests import tagged
from odoo.addons.project.tests.test_project_base import TestProjectCommon
@tagged('-at_install', 'post_install', 'task_dependencies')
class TestTaskDependencies(TestProjectCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.project_pigs.write({
'allow_task_dependencies': True,
})
cls.task_3 = cls.env['project.task'].with_context({'mail_create_nolog': True}).create({
'name': 'Pigs UserTask 2',
'user_id': cls.user_projectuser.id,
'project_id': cls.project_pigs.id,
})
def test_task_dependencies(self):
""" Test the task dependencies feature
Test Case:
=========
1) Add task2 as dependency in task1
2) Checks if the task1 has the task in depend_on_ids field.
"""
self.assertEqual(len(self.task_1.depend_on_ids), 0, "The task 1 should not have any dependency.")
self.task_1.write({
'depend_on_ids': [Command.link(self.task_2.id)],
})
self.assertEqual(len(self.task_1.depend_on_ids), 1, "The task 1 should have a dependency.")
self.task_1.write({
'depend_on_ids': [Command.link(self.task_3.id)],
})
self.assertEqual(len(self.task_1.depend_on_ids), 2, "The task 1 should have two dependencies.")
+1
View File
@@ -11,6 +11,7 @@
<script type="text/javascript" src="/project/static/src/js/tours/project.js"></script>
<script type="text/javascript" src="/project/static/src/js/project_calendar.js"></script>
<link rel="stylesheet" type="text/scss" href="/project/static/src/scss/project_dashboard.scss"/>
<link rel="stylesheet" type="text/scss" href="/project/static/src/scss/project_form.scss"/>
</xpath>
</template>
+18
View File
@@ -658,6 +658,7 @@
<field name="repeat_show_week" invisible="1" />
<field name="repeat_show_month" invisible="1" />
<field name="recurrence_id" invisible="1" />
<field name="allow_task_dependencies" invisible="1" />
<header>
<button name="action_assign_to_me" string="Assign to Me" type="object" class="oe_highlight"
attrs="{'invisible' : [('user_id', '!=', False)]}"/>
@@ -799,6 +800,23 @@
</group>
</group>
</page>
<page name="task_dependencies" string="Blocked By" attrs="{'invisible': [('allow_task_dependencies', '=', False)]}" groups="project.group_project_task_dependencies">
<field name="depend_on_ids" nolabel="1">
<tree editable="bottom">
<field name="is_closed" invisible="1" />
<field name="name" />
<field name="project_id" optional="hide" />
<field name="user_id" widget="many2one_avatar_user" optional="show"/>
<field name="company_id" optional="hide" groups="base.group_multi_company" />
<field name="activity_ids" widget="list_activity" optional="hide"/>
<field name="date_deadline" attrs="{'invisible': [('is_closed', '=', True)]}" optional="show" />
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" optional="hide"/>
<field name="kanban_state" widget="state_selection" optional="hide" />
<field name="stage_id" optional="show" />
<button class="oe_link float-right" string="View Task" name="action_open_task_form" type="object"/>
</tree>
</field>
</page>
</notebook>
</sheet>
<div class="oe_chatter">