Fix weekly summary crash on open entries

print_summary_weekly, print_summary_weekly_totals and _aggregate summed
raw duration_hours, which is None for open (unfinished) entries, raising
TypeError: float + NoneType. Skip open entries from the weekly totals,
matching to_csv_entries and parser.aggregate. Add regression tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jef Roosens 2026-05-30 19:57:36 +02:00
parent b2b45fd4e1
commit 8f5232d1fe
Signed by: Jef Roosens
GPG key ID: 119385BCAA005C21
2 changed files with 50 additions and 2 deletions

View file

@ -163,7 +163,12 @@ def print_summary_weekly(
day_sections: list[tuple[date, list[dict]]], project_map: dict
) -> None:
"""Print a full summary for each day of the week."""
week_total = sum(e["duration_hours"] for _, rows in day_sections for e in rows)
week_total = sum(
e["duration_hours"]
for _, rows in day_sections
for e in rows
if e["duration_hours"] is not None
)
for day, rows in day_sections:
aggregated = _aggregate(rows)
day_total = sum(e["quantity"] for e in aggregated)
@ -221,7 +226,9 @@ def print_summary_weekly_totals(
rows_out = []
for day, rows in day_sections:
day_total = sum(e["duration_hours"] for e in rows)
day_total = sum(
e["duration_hours"] for e in rows if e["duration_hours"] is not None
)
week_total += day_total
rows_out.append((day.strftime("%A"), day.strftime("%Y-%m-%d"), day_total))
@ -245,6 +252,8 @@ def _aggregate(rows: list[dict]) -> list[dict]:
key_order: list[tuple] = []
totals: dict[tuple, float] = defaultdict(float)
for row in rows:
if row["duration_hours"] is None:
continue
description = build_description(row["story"], row["note"])
key = (row["project"].strip(), description)
if key not in totals: