Give tips a date, a scope per child, and a dismissal that sticks

Three faults, all invisible while the tests passed. Advice was built for the
first child only, so a second child got none. The planned days feeding every
count were fetched once per parent and appended to one list, so a couple's
days were counted twice and every intensity and projection derived from them
was wrong. And dismissing a tip forgot the moment the page reloaded.

Tips now carry the date they concern, lifted from figures the rules already
computed, so a view of a month can show only what applies to it. They are
built per child and identified per child, so the same rule firing for two
children is two separate pieces of advice.

A dismissal is stored against a fingerprint of the facts that were dismissed.
When those facts change the advice returns with its new numbers, rather than
one click silencing a warning about a forfeiture that keeps growing.
This commit is contained in:
2026-09-17 22:32:03 +02:00
parent c15cd44cb4
commit fdbfb7d580
20 changed files with 1396 additions and 57 deletions
+30
View File
@@ -0,0 +1,30 @@
"""Domain entity: TipDismissal.
A workspace-scoped record that a specific tip (`Tip.id`, see
`app.services.tips_service`) has been acknowledged/dismissed by the user.
Keyed by (workspace_id, tip_id) — see the UNIQUE constraint on the
`tip_dismissal` table — so re-dismissing the same tip refreshes `data_hash`
and `dismissed_at` instead of creating a duplicate row.
`data_hash` snapshots `app.utils.tip_predicates.hash_tip_data(tip.data)` at
dismiss time. `TipsService` only treats a dismissal as active while the
rule's *current* output hashes to the same value — once the underlying
numbers move (more days now projected to expire at age 4, a different
`fourth_birthday`, ...), the dismissal is stale and the tip resurfaces. See
`TipsService._filter_dismissed` for why: permanently silencing a warning like
`preserve_for_age_4` because its *old* figures were once dismissed would be
dangerous.
"""
from dataclasses import dataclass
from datetime import datetime
from uuid import UUID
@dataclass
class TipDismissal:
id: UUID
workspace_id: UUID
tip_id: str
data_hash: str
dismissed_at: datetime | None = None