Before this PR the task state was fixed by the kanban_state field which was useful when you use the stage of the project as parts of a pipeline, but not relevant when users are using stages as bucket lists. (specific examples at the end of the specs) The goal of this PR is to provide users a way to mark their tasks as done with a simple button press, while keeping the option to label a task as Approved, Canceled or Requesting changes like in the old kanban_state field. The kanban_state of a task had no impact whatsoever on other tasks of the pipe, we would like to change that and make the task state have an influence on its dependent tasks. The state will also have influence over the 'recurrent' tasks (to be implemented in Task #3084945) If you want a better description of those changes with screenshot and colors check specs of: Task-3084930 PRs: See odoo/enterprise#35359 See odoo/upgrade#4367 ----------------------------------------- Interaction with blocking tasks: the closed values which mark the task as closed or finished: - Done - Canceled The Open values when the task isn't finished yet: - In progress - Changes Requested - Approved - Waiting (which is not selectable) Where to change the state of a task: - For kanban and form views: same place as kanban_state (bottom right of kanban card, top right of form view) - For list view: left of list (after task priority) more details about the state widget in state field widgets part Interaction with existing fields - is_closed: which was determined by the task.stage_id.fold, now a task is closed when in one of the following stages - Done - Canceled a closed task is considered as finished, the time of the closing will be stored in the date_last_stage_update field - is_blocked: a task is considered blocked if ANY of its blocking task is in one of the blocking states (more details about this in the following part Interaction with blocking tasks): - in Progress - Changes Requested - Approved - Waiting !! important !! is_closed and is_blocked are not mutually exclusive, you can have a task that blocked and is closed at the same time, the reason why will be explained late date_last_stage_update: this field is updated everytime the task goes into a closing state OR when the task changes stage. We need to check that the value is updated in each case (using the already available filter) Interaction with blocking tasks the state of a task can now be changed by its blocking tasks following the logic: if ANY of the blocking tasks is NOT closed (so its state is in one of the open values) the task is considered as blocked - if a task is blocked and NOT closed its state will switch to Waiting - the Waiting state will display an unclickable hourglass icon on the task kanban/list views, once in the waiting state you can't change the state of the taskfrom the kanban/list views - a blocked task state can be changed through the form view, so you can override the 'block' by choosing a closed state (only done or canceled) - once overriden, the task will change to the closed state the user wants, but the task is still blocked so in case where the user comes back to an open state, the task will automatically switch back to the waiting state (according to the state before the block) - if the blocking task switches to a non-blocking state, the task will not be considered as blocked anymore and its state will switch back to In Progress Default values the default value is always in progress Special cases when a task is moved from a stage to another one - if the state was in one of the open states (approved, changes requested, in progress ) the state goes back to In Progress - if not, the state stays the same when a task is moved from a project to another one - the state goes back to In Progress when a task is duplicated - if the state was in one of the open states (approved, changes requested, in progress ) the state goes back to In Progress - if not, the state stays the same closes odoo/odoo#107593 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
240 lines
11 KiB
Python
240 lines
11 KiB
Python
# -*- 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
|
|
|
|
from datetime import date
|
|
|
|
|
|
@tagged('-at_install', 'post_install')
|
|
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_ids': cls.user_projectuser,
|
|
'project_id': cls.project_pigs.id,
|
|
})
|
|
|
|
def flush_tracking(self):
|
|
""" Force the creation of tracking values. """
|
|
self.env.flush_all()
|
|
self.cr.precommit.run()
|
|
|
|
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.")
|
|
|
|
def test_cyclic_dependencies(self):
|
|
""" Test the cyclic dependencies
|
|
|
|
Test Case:
|
|
=========
|
|
1) Check initial setting on three tasks
|
|
2) Add task2 as dependency in task1
|
|
3) Add task3 as dependency in task2
|
|
4) Add task1 as dependency in task3 and check a validation error is raised
|
|
5) Add task1 as dependency in task2 and check a validation error is raised
|
|
"""
|
|
# 1) Check initial setting on three tasks
|
|
self.assertTrue(
|
|
len(self.task_1.depend_on_ids) == len(self.task_2.depend_on_ids) == len(self.task_3.depend_on_ids) == 0,
|
|
"The three tasks should depend on no tasks.")
|
|
self.assertTrue(self.task_1.allow_task_dependencies, 'The task dependencies feature should be enable.')
|
|
self.assertTrue(self.task_2.allow_task_dependencies, 'The task dependencies feature should be enable.')
|
|
self.assertTrue(self.task_3.allow_task_dependencies, 'The task dependencies feature should be enable.')
|
|
|
|
# 2) Add task2 as dependency in task1
|
|
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 one dependency.')
|
|
|
|
# 3) Add task3 as dependency in task2
|
|
self.task_2.write({
|
|
'depend_on_ids': [Command.link(self.task_3.id)],
|
|
})
|
|
self.assertEqual(len(self.task_2.depend_on_ids), 1, "The task 2 should have one dependency.")
|
|
|
|
# 4) Add task1 as dependency in task3 and check a validation error is raised
|
|
with self.assertRaises(ValidationError), self.cr.savepoint():
|
|
self.task_3.write({
|
|
'depend_on_ids': [Command.link(self.task_1.id)],
|
|
})
|
|
self.assertEqual(len(self.task_3.depend_on_ids), 0, "The dependency should not be added in the task 3 because of a cyclic dependency.")
|
|
|
|
# 5) Add task1 as dependency in task2 and check a validation error is raised
|
|
with self.assertRaises(ValidationError), self.cr.savepoint():
|
|
self.task_2.write({
|
|
'depend_on_ids': [Command.link(self.task_1.id)],
|
|
})
|
|
self.assertEqual(len(self.task_2.depend_on_ids), 1, "The number of dependencies should no change in the task 2 because of a cyclic dependency.")
|
|
|
|
def test_tracking_dependencies(self):
|
|
# Enable the company setting
|
|
self.env['res.config.settings'].create({
|
|
'group_project_task_dependencies': True
|
|
}).execute()
|
|
# `depend_on_ids` is tracked
|
|
self.task_1.with_context(mail_notrack=True).write({
|
|
'depend_on_ids': [Command.link(self.task_2.id)]
|
|
})
|
|
self.cr.precommit.clear()
|
|
# Check that adding a dependency changes the stage then logs a message in task_1
|
|
self.flush_tracking()
|
|
self.assertEqual(len(self.task_1.message_ids), 1,
|
|
'Adding task 2 as a dependencie should have logged a message in task 1.')
|
|
|
|
# Check that changing a dependency tracked field in task_2 logs a message in task_1.
|
|
self.task_2.write({'date_deadline': date(1983, 3, 1)}) # + 1 message in task_1 and task_2
|
|
self.flush_tracking()
|
|
self.assertEqual(len(self.task_1.message_ids), 2,
|
|
'Changing the deadline on task 2 should have logged a message in task 1.')
|
|
|
|
# Check that changing a dependency tracked field in task_1 does not log a message in task_2.
|
|
self.task_1.date_deadline = date(2020, 1, 2) # + 1 message in task_1
|
|
self.flush_tracking()
|
|
self.assertEqual(len(self.task_2.message_ids), 1,
|
|
'Changing the deadline on task 1 should not have logged a message in task 2.')
|
|
|
|
# Check that changing a field that is not tracked at all on task 2 does not impact task 1.
|
|
self.task_2.color = 100 # no new message
|
|
self.flush_tracking()
|
|
self.assertEqual(len(self.task_1.message_ids), 3,
|
|
'Changing the color on task 2 should not have logged a message in task 1 since it is not tracked.')
|
|
|
|
# Check that changing multiple fields does not log more than one message.
|
|
self.task_2.write({
|
|
'date_deadline': date(2020, 1, 1),
|
|
'state': '02_changes_requested',
|
|
}) # + 1 message in task_1 and task_2
|
|
self.flush_tracking()
|
|
self.assertEqual(len(self.task_1.message_ids), 4,
|
|
'Changing multiple fields on task 2 should only log one message in task 1.')
|
|
|
|
def test_task_dependencies_settings_change(self):
|
|
|
|
def set_task_dependencies_setting(enabled):
|
|
features_config = self.env["res.config.settings"].create({'group_project_task_dependencies': enabled})
|
|
features_config.execute()
|
|
|
|
self.project_pigs.write({
|
|
'allow_task_dependencies': False,
|
|
})
|
|
|
|
# As the Project General Setting group_project_task_dependencies needs to be toggled in order
|
|
# to be applied on the existing projects we need to force it so that it does not depends on anything
|
|
# (like demo data for instance)
|
|
set_task_dependencies_setting(False)
|
|
set_task_dependencies_setting(True)
|
|
self.assertTrue(self.project_pigs.allow_task_dependencies, "Projects allow_task_dependencies should follow group_project_task_dependencies setting changes")
|
|
|
|
self.project_chickens = self.env['project.project'].create({
|
|
'name': 'My Chicken Project'
|
|
})
|
|
self.assertTrue(self.project_chickens.allow_task_dependencies, "New Projects allow_task_dependencies should default to group_project_task_dependencies")
|
|
|
|
set_task_dependencies_setting(False)
|
|
self.assertFalse(self.project_pigs.allow_task_dependencies, "Projects allow_task_dependencies should follow group_project_task_dependencies setting changes")
|
|
|
|
self.project_ducks = self.env['project.project'].create({
|
|
'name': 'My Ducks Project'
|
|
})
|
|
self.assertFalse(self.project_ducks.allow_task_dependencies, "New Projects allow_task_dependencies should default to group_project_task_dependencies")
|
|
|
|
def test_duplicate_project_with_task_dependencies(self):
|
|
self.project_pigs.allow_task_dependencies = True
|
|
self.task_1.depend_on_ids = self.task_2
|
|
pigs_copy = self.project_pigs.copy()
|
|
|
|
task1_copy = pigs_copy.task_ids.filtered(lambda t: t.name == 'Pigs UserTask')
|
|
task2_copy = pigs_copy.task_ids.filtered(lambda t: t.name == 'Pigs ManagerTask')
|
|
|
|
self.assertEqual(len(task1_copy), 1, "Should only contain 1 copy of UserTask")
|
|
self.assertEqual(len(task2_copy), 1, "Should only contain 1 copy of ManagerTask")
|
|
|
|
self.assertEqual(task1_copy.depend_on_ids.ids, [task2_copy.id],
|
|
"Copy should only create a relation between both copy if they are both part of the project")
|
|
|
|
task1_copy.depend_on_ids = self.task_1
|
|
|
|
pigs_copy_copy = pigs_copy.copy()
|
|
task1_copy_copy = pigs_copy_copy.task_ids.filtered(lambda t: t.name == 'Pigs UserTask')
|
|
|
|
self.assertEqual(task1_copy_copy.depend_on_ids.ids, [self.task_1.id],
|
|
"Copy should not alter the relation if the other task is in a different project")
|
|
|
|
def test_duplicate_project_with_subtask_dependencies(self):
|
|
self.project_goats.allow_task_dependencies = True
|
|
self.project_goats.allow_subtasks = True
|
|
parent_task = self.env['project.task'].with_context({'mail_create_nolog': True}).create({
|
|
'name': 'Parent Task',
|
|
'project_id': self.project_goats.id,
|
|
'child_ids': [
|
|
Command.create({'name': 'Node 1'}),
|
|
Command.create({'name': 'SuperNode 2', 'child_ids': [Command.create({'name': 'Node 2'})]}),
|
|
Command.create({'name': 'Node 3'}),
|
|
],
|
|
})
|
|
|
|
node1 = parent_task.child_ids[0]
|
|
node2 = parent_task.child_ids[1].child_ids
|
|
node3 = parent_task.child_ids[2]
|
|
|
|
node1.dependent_ids = node2
|
|
node2.dependent_ids = node3
|
|
|
|
# Test copying the whole Node tree
|
|
parent_task_copy = parent_task.copy()
|
|
parent_copy_node1 = parent_task_copy.child_ids[0]
|
|
parent_copy_node2 = parent_task_copy.child_ids[1].child_ids
|
|
parent_copy_node3 = parent_task_copy.child_ids[2]
|
|
|
|
# Relation should only be copied between the newly created node
|
|
self.assertEqual(len(parent_copy_node1.dependent_ids), 1)
|
|
self.assertEqual(parent_copy_node1.dependent_ids.ids, parent_copy_node2.ids, 'Node1copy - Node2copy relation should be present')
|
|
self.assertEqual(len(parent_copy_node2.dependent_ids), 1)
|
|
self.assertEqual(parent_copy_node2.dependent_ids.ids, parent_copy_node3.ids, 'Node2copy - Node3copy relation should be present')
|
|
|
|
# Original Node should not have new relation
|
|
self.assertEqual(len(node1.dependent_ids), 1)
|
|
self.assertEqual(node1.dependent_ids.ids, node2.ids, 'Only Node1 - Node2 relation should be present')
|
|
self.assertEqual(len(node2.dependent_ids), 1)
|
|
self.assertEqual(node2.dependent_ids.ids, node3.ids, 'Only Node2 - Node3 relation should be present')
|
|
|
|
# Test copying Node inside the chain
|
|
single_copy_node2 = node2.copy()
|
|
|
|
# Relation should be present between the other original node and the newly copied node
|
|
self.assertEqual(len(single_copy_node2.depend_on_ids), 1)
|
|
self.assertEqual(single_copy_node2.depend_on_ids.ids, node1.ids, 'Node1 - Node2copy relation should be present')
|
|
self.assertEqual(len(single_copy_node2.dependent_ids), 1)
|
|
self.assertEqual(single_copy_node2.dependent_ids.ids, node3.ids, 'Node2copy - Node3 relation should be present')
|
|
|
|
# Original Node should have new relations
|
|
self.assertEqual(len(node1.dependent_ids), 2)
|
|
self.assertEqual(len(node3.depend_on_ids), 2)
|