Files
odoo_source/addons/project/tests/test_task_state.py
T
Bastien (bvdn) 2e78356f82 [IMP] project,*: create new task.state Selection field
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>
2023-03-08 21:33:03 +01:00

140 lines
6.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.fields import Command
from odoo.tests import tagged
from odoo.addons.project.tests.test_project_base import TestProjectCommon
@tagged('-at_install', 'post_install')
class TestTaskState(TestProjectCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.project_goats.write({
'allow_task_dependencies': True,
})
(cls.task_1 + cls.task_2).write({
'project_id': cls.project_goats.id,
})
def test_base_state(self):
""" Test the task base state features
Test Case:
=========
1) check that task_1 and task_2 are in_progress by default
2) add task_2 as a dependency for task_1, check that task_1 state has gone to waiting_normal.
3) force task_1 state to done, the state of task_1 should become done
4) switch task_1 state back to in progress, its state should automatically switch back to waiting normal because of the task_2 dependency
5) change task_2 state to canceled, check that task_1 state has gone back to in_progress.
"""
# 1) check that task_1 and task2 are in_progress by default
self.assertEqual(self.task_1.state, '01_in_progress', "The task_1 should be in progress by default")
self.assertEqual(self.task_2.state, '01_in_progress', "The task_2 should be in progress by default")
# 2) add task2 as a dependency for task 1, check that task_1 state has gone to waiting_normal.
self.task_1.write({
'depend_on_ids': [Command.link(self.task_2.id)],
})
self.assertEqual(self.task_1.state, '04_waiting_normal', "The task_1 should be in waiting_normal after depending on another open task")
# 3) force task_1 state to done, the state of task_1 should become done
self.task_1.write({
'state': '1_done',
})
self.assertEqual(self.task_1.state, '1_done', "The task_1 should be in done even if it has a depending task not closed")
# 4) switch task_1 state back to in progress, its state should automatically switch back to waiting normal because of the task2 dependency
self.task_1.write({
'state': '01_in_progress',
})
self.assertEqual(self.task_1.state, '04_waiting_normal', "task_1 state should automatically switch back to waiting_normal because of the task2 dependency")
# 5) change task_2 state to done, check that task_1 state has gone back to in_progress.
self.task_2.write({
'state': '1_canceled',
})
self.assertEqual(self.task_1.state, '01_in_progress', "task_1 state should automatically switch back to in_progress when its dependency closes")
def test_change_stage_or_project(self):
"""
Test special cases where the task is moved from a stage to another or a project to another
Test Case:
=========
1) change task_1 to an open state and task_2 to a closed state
2) change task_1 and task_2 stage, task_1 should go back to in_progress, task_2 should stay in its closing state
3) change task_1 and task_2 project, they should both go back to in_progress
"""
# 1) change task_1 to an open state and task_2 to a closed state
stage_won = self.env['project.task.type'].search([('name', '=', 'Won')])
project_pigs = self.env['project.project'].search([('name', '=', 'Pigs')])
self.task_1.write({
'state': '02_changes_requested',
})
self.task_2.write({
'state': '1_canceled',
})
# 2) change task_1 and task_2 from stage, task_1 should go back to in_progress, task_2 should stay in its closing state
(self.task_1 + self.task_2).write({
'stage_id': stage_won.id,
})
self.task_1._onchange_stage_id()
self.task_2._onchange_stage_id()
self.assertEqual(self.task_1.state, '01_in_progress', "task_1 state should automatically switch back to in_progress when its stage changes")
self.assertEqual(self.task_2.state, '1_canceled', "task_2 state should stay in its closed state")
# 3) change task_1 and task_2 project, they should both go back to in_progress
# we make change the task_1 state back to an open state
self.task_1.write({
'state': '02_changes_requested',
})
(self.task_1 + self.task_2).write({
'project_id': project_pigs.id
})
self.task_1._onchange_project_id()
self.task_2._onchange_project_id()
self.assertEqual(self.task_1.state, '01_in_progress', "task_1 state should automatically switch back to in_progress when its project changes")
self.assertEqual(self.task_2.state, '01_in_progress', "task_2 state should automatically switch back to in_progress when its project changes")
def test_duplicate_dependent_task(self):
self.task_1.write({
'depend_on_ids': [Command.link(self.task_2.id)],
})
self.assertEqual(self.task_1.state, '04_waiting_normal', "The task_1 should be in waiting_normal after depending on another open task")
self.task_1_copy = self.task_1.copy()
self.assertEqual(self.task_1.state, '04_waiting_normal', "The task_1_copy should keep his dependence and stay in waiting_normal")
self.task_2.write({
'state': '03_approved',
})
self.task_2_copy = self.task_2.copy()
self.assertEqual(self.task_2_copy.state, '01_in_progress', "The task_2_copy should go back to in_progress")
self.task_2.write({
'state': '1_done',
})
self.assertEqual(self.task_1.state, '04_waiting_normal', "The task_1 should have both tasks as dependencies and so should stay in waiting when one of the two is completed")
self.assertEqual(self.task_1_copy.state, '04_waiting_normal', "The task_1_copy should have both tasks as dependencies and so should stay in waiting when one of the two is completed")
self.task_2_copy.write({
'state': '1_done',
})
self.assertEqual(self.task_1.state, '01_in_progress', "The task_1 should have both tasks as dependencies and so should stay go to 'done' when both dependencies are completed")
self.assertEqual(self.task_1_copy.state, '01_in_progress', "The task_1_copy should have both tasks as dependencies and so should stay go to 'done' when both dependencies are completed")