diff --git a/backend/app/routers/todos.py b/backend/app/routers/todos.py index 99c3cf5..1235d49 100644 --- a/backend/app/routers/todos.py +++ b/backend/app/routers/todos.py @@ -192,6 +192,22 @@ async def update_todo( for key, value in update_data.items(): setattr(todo, key, value) + # Recalculate recurrence schedule if the todo is completed and now + # has a recurrence rule (e.g. user edited a completed todo to add + # recurrence, or changed the rule/due_date while completed). + if todo.completed and todo.recurrence_rule: + reset_at, next_due = _calculate_recurrence( + todo.recurrence_rule, + todo.due_date, + current_user.first_day_of_week, + ) + todo.reset_at = reset_at + todo.next_due_date = next_due + elif todo.completed and not todo.recurrence_rule: + # Recurrence removed while completed — clear schedule + todo.reset_at = None + todo.next_due_date = None + await db.commit() await db.refresh(todo)