[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) <xbo@odoo.com>
This commit is contained in:
paso-odoo
2023-06-29 00:18:45 +02:00
parent d31ad80f9a
commit d8481fee6a
+2 -2
View File
@@ -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