Hello
I'm using Odoo 19 with Studio and need help with an automation issue.
**Goal:**
Update the `date_deadline` field in all tasks when the `date_start` field is modified in the parent project.
Problem: The code executes without errors, but the task deadlines are not updated. Any ideas what could be wrong? Thanks!
for task in env['project.task'].search([('project_id', '=', record.id)]):
task.sudo().write({'date_deadline': "2026-09-01"})
Try with this values:
2026-09-01 00:00:00
Please try to proceed without sudo in write.. it might be avoid something.
I’ve tried, but the field still hasn’t been updated
I’ve tried, without sudo in write, but the field still hasn’t been updated
Thank you, indeed it's about the trigger. I have a new problem: I improved my code, but I can't add days to a date. I get the following error: NameError: name 'timedelta' is not defined."*
"I tried importing timedelta, but it doesn't seem to be allowed."
for task in env['project.task'].search([('project_id', '=', record.id)]):
# 1. Récupérer la valeur (ex: "+10" ou "-5")
increment_str = task.x_studio_j_ or "+0" # Valeur par défaut "+0" si vide
# 2. Vérifier le signe et calculer
if increment_str.startswith('+'):
days_toadd = int(increment_str[1:]) # Prend le nombre après le +
task.write({'date_deadline' : (record.x_studio_date_j0) + timedelta(days=days_toadd)})
elif increment_str.startswith('-'):
days = int(increment_str[1:]) # Prend le nombre après le -
task.write({'date_deadline' : (record.x_studio_date_j0) + timedelta(days=days_toadd)})
else:
new_date = fields.Date.from_string(record.x_studio_date_j0) # Pas de changement si format invalide