Fix first occurrence missing from recurring events

The parent template is hidden from the calendar listing, but the
recurrence service was only generating children starting from the
second occurrence. Now generates a child for the parent's own start
date so the first occurrence is always visible.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kyle 2026-02-22 01:55:50 +08:00
parent 1a707ff179
commit 3b63d18f63

View File

@ -84,6 +84,11 @@ def generate_occurrences(
original_start=occ_start,
)
# Always generate a child for the parent's own start date (the first occurrence).
# The parent template is hidden from list views, so without this the first date
# would have no visible event.
occurrences.append(_make_child(parent_start))
if rule_type == "every_n_days":
interval: int = int(rule.get("interval") or 1)
if interval < 1:
@ -95,10 +100,10 @@ def generate_occurrences(
elif rule_type == "weekly":
weekday: int = int(rule.get("weekday") if rule.get("weekday") is not None else parent_start.weekday())
# Start from the week after the parent
# Start from the next week after the parent
days_ahead = (weekday - parent_start.weekday()) % 7
if days_ahead == 0:
days_ahead = 7 # skip the parent's own week
days_ahead = 7
current = parent_start + timedelta(days=days_ahead)
while current < horizon:
occurrences.append(_make_child(current))