Files
odoo_source/addons/project/tests/test_task_dependencies.py
T
c5dd03ffee [FIX] project: review UX and UI in Project app
This commit reviews the UX and UI in Project app and improves the usability of the
new features recently added (subtasks list in kanban card, state field replacing
kanban_state field, etc).

The following changes are made in this commit:

- swap of user_id icon in the kanban box and the removal of the allow_unassign field and setting
- change the ordering of the fields in the subtask list
- make small layout changes in the project.task and project.project kanban cards
- remove the "lock-icon private" sub-title of private tasks, replace it with a
  little lock icon on the bottom right icons of the kanban card.
- remove the break tag in the project.task kanban card that was unecessary
  given the new display and margin style settings
- lock icon is bigger
- kanban icons are better aligned
- state is as big as avatar
- remove the 'remaining hours on SO' field
- deadline field will be optional and hidden by default in project.task list view
- remove the rating field
- add stage field as optional in project.task list views
- priority and state fields will no longer be optional
- stage_id will be copied when duplicating a task, except when the task is
  generated through the recurrence
- remove the tooltip of the tag_ids field
- When duplicating a task having sub-tasks, '(copy)' is no longer
  added to the name of the sub-tasks of this task.
- project.task kanban view:
  * (+ x tasks) mention next to the name is removed
  * The caret is replaced with 'fa-check-square-o x/y'
    which will represent the number of sub-tasks closed
    compared to the total number of sub-tasks
  * Only open subtasks are displayed
  * When changing the state of a sub-task to a closing one,
    the sub-task is muted and removed from the list on the view reload
  * The name of the parent task on the kanban card of sub-tasks is
    displayed except when viewing the sub-tasks of a particular task
    through the sub-tasks stat button
  * project.project kanban view: the fa-check-square-o icon of
    milestones is replaced with fa-flag-o
  * project.task kanban card: the fa-play and fa-pause icons
    are moved on the right of the remaining hours widge.
  * Allow users to edit the stage_id in batch from the list view of tasks
    if all of the selected tasks are part of the same project.
  * the state will have the same size as the avatar
  * change the opacity of the tasks that are closed
  * state is at the right of subtask list
  * the striked should be replaced by the opacity on the kanban card

Enterprise PR: odoo/enterprise#38132

Task-3229873

closes odoo/odoo#116628

X-original-commit: 09b5d5843096d27b5a4ab0f603ad44bdb2e74723
Related: odoo/upgrade#4478
Related: odoo/enterprise#38771
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
Co-authored-by: Panagiotis Kyriakou <paky@odoo.com>
Co-authored-by: Bastien (bvdn) <bvdn@odoo.com>
2023-04-03 17:07:21 +02:00

239 lines
12 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
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', 'project_id': self.project_goats.id}),
Command.create({'name': 'SuperNode 2', 'project_id': self.project_goats.id, 'child_ids': [Command.create({'name': 'Node 2', 'project_id': self.project_goats.id})]}),
Command.create({'name': 'Node 3', 'project_id': self.project_goats.id}),
],
})
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)