Calculate recurrence schedule on todo update, not just toggle

When editing an already-completed todo to add/change recurrence or
due_date, recalculate reset_at and next_due_date so the reset info
displays immediately without needing to uncomplete and re-complete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kyle 2026-02-23 20:09:42 +08:00
parent 07cfbabcf0
commit 66ad8902d7

View File

@ -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)