[FIX] project: allow state reset for stage batch modification

The onchange on the stage_id/project_id wasn't triggered when modifing tasks in batch
we are now putting the same conditions as the onchange but in the task write() method

closes odoo/odoo#139491

X-original-commit: 0accffc0eb65f40e44d31402a0a362abaaa9b9bd
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Bastien (bvdn)
2023-10-25 17:03:20 +00:00
parent 998ef1f63a
commit 78f551b2fc
3 changed files with 5 additions and 11 deletions
+4 -7
View File
@@ -292,7 +292,7 @@ class Task(models.Model):
for task in self:
task.analytic_account_id = task.project_id.analytic_account_id
@api.depends('depend_on_ids.state', 'project_id.allow_task_dependencies')
@api.depends('stage_id', 'depend_on_ids.state', 'project_id.allow_task_dependencies')
def _compute_state(self):
for task in self:
dependent_open_tasks = []
@@ -304,14 +304,9 @@ class Task(models.Model):
if task.state not in CLOSED_STATES:
task.state = '04_waiting_normal'
# if the task as no blocking dependencies and is in waiting_normal, the task goes back to in progress
elif task.state == '04_waiting_normal':
elif task.state not in CLOSED_STATES:
task.state = '01_in_progress'
@api.onchange('stage_id')
def _onchange_stage_id(self):
if self.state != '04_waiting_normal' and self.state not in CLOSED_STATES:
self.state = '01_in_progress'
@api.onchange('project_id')
def _onchange_project_id(self):
if self.state != '04_waiting_normal':
@@ -1106,6 +1101,8 @@ class Task(models.Model):
if task.is_blocked_by_dependences() and vals['state'] not in CLOSED_STATES and vals['state'] != '04_waiting_normal':
task.state = '04_waiting_normal'
task.date_last_stage_update = now
elif 'project_id' in vals:
self.filtered(lambda t: t.state != '04_waiting_normal').state = '01_in_progress'
self._task_message_auto_subscribe_notify({task: task.user_ids - old_user_ids[task] - self.env.user for task in self})
return result
@@ -314,9 +314,9 @@ class TestProjectMilestone(TestProjectCommon):
"The child milestone should be updated if the parent task's project is changed only if dislay_on_project is set to False for the subtask.")
# J. Same case as F but subtask is closed -> no update of its milestone
task_2.state = '1_done'
self.task_1.project_id = task_2.project_id = self.project_pigs
self.task_1.milestone_id = task_2.milestone_id = self.milestone_pigs
task_2.state = '1_done'
self.assertEqual(task_2.milestone_id, self.milestone_pigs)
self.assertEqual(self.task_1.milestone_id, self.milestone_pigs)
-3
View File
@@ -90,8 +90,6 @@ class TestTaskState(TestProjectCommon):
(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")
@@ -106,7 +104,6 @@ class TestTaskState(TestProjectCommon):
'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")