From 78f551b2fc6d24ce38bbb0207d0c0bb9b78bc880 Mon Sep 17 00:00:00 2001 From: "Bastien (bvdn)" Date: Thu, 19 Oct 2023 16:18:07 +0000 Subject: [PATCH] [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) --- addons/project/models/project_task.py | 11 ++++------- addons/project/tests/test_project_milestone.py | 2 +- addons/project/tests/test_task_state.py | 3 --- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/addons/project/models/project_task.py b/addons/project/models/project_task.py index 04b6e34b450..ce803ffb9d8 100644 --- a/addons/project/models/project_task.py +++ b/addons/project/models/project_task.py @@ -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 diff --git a/addons/project/tests/test_project_milestone.py b/addons/project/tests/test_project_milestone.py index 535b023d8ed..996c52b94db 100644 --- a/addons/project/tests/test_project_milestone.py +++ b/addons/project/tests/test_project_milestone.py @@ -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) diff --git a/addons/project/tests/test_task_state.py b/addons/project/tests/test_task_state.py index 029fb94b649..3f0f5c21538 100644 --- a/addons/project/tests/test_task_state.py +++ b/addons/project/tests/test_task_state.py @@ -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")