From d8481fee6a184b22e9e97c22d8e17b02b07b7ed6 Mon Sep 17 00:00:00 2001 From: paso-odoo Date: Tue, 27 Jun 2023 10:25:07 +0000 Subject: [PATCH] [FIX] project: local variable task referenced in write When a user creates the task without a name field and directly clicks on the 'Mark as Done' button, will give UnboundLocalError like the local variable 'task' referenced before assignment. Steps to produce: - Install the 'Field Service' module. - Field Service > My Tasks > Open any task. - Make the name field unrequired (Studio or Edit form View) - Create a new task > Set the Customer field and leave the Name field as blank. - Before saving the task click on the 'Mark as Done' button > Discard Changes. - Error will be produced. Fixing the indentation for `task.date_last_stage_update = now` will solve this issue. We have used the task variable in for loop. Sentry-4276832131 closes odoo/odoo#126752 X-original-commit: c3649a32c98d7093610a4367b1e72c1b4b0085b7 Signed-off-by: Xavier Bol (xbo) --- addons/project/models/project_task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/project/models/project_task.py b/addons/project/models/project_task.py index 2ae033362d1..8651ac3c507 100644 --- a/addons/project/models/project_task.py +++ b/addons/project/models/project_task.py @@ -1087,8 +1087,8 @@ class Task(models.Model): if task.allow_task_dependencies: if task.is_blocked_by_dependences() and vals['state'] not in CLOSED_STATES and vals['state'] != '04_waiting_normal': task.state = '04_waiting_normal' - if vals['state'] in CLOSED_STATES: - task.date_last_stage_update = now + if vals['state'] in CLOSED_STATES: + task.date_last_stage_update = now self._task_message_auto_subscribe_notify({task: task.user_ids - old_user_ids[task] - self.env.user for task in self}) return result