# FamilyDashboard shared daily bonus tasks

Use when changing FamilyDashboard bonus-task completion semantics, task templates created for “both” children, or Admin task creation layout.

## Behaviour to preserve

- Bonus tasks that represent one family-level opportunity for the day must be completable only once per date.
- Current data/admin flows may still have one `TaskTemplate` per child. Do not rely on a shared `task_template_id` for “both” tasks.
- Group shared daily bonus instances by stable daily instance fields:
  - `task_date`
  - `kind == bonus`
  - same `title`
  - not `cancelled`
- Completing any task in the group:
  - marks all matching child instances `done` with the same completion timestamp;
  - creates `TaskCompletion` rows for each instance so reload/status audit stays coherent;
  - books exactly one positive `CoinTransaction`, for the child whose task was tapped.
- Undoing any done task in the group:
  - reopens all matching instances;
  - marks their open completions as undone;
  - books exactly one counter-transaction against the original earned transaction, preserving `reference_transaction_id` when available.
- Required/study tasks must keep normal per-child semantics and must still run penalty reversal logic.
- Bonus completion should not run day-close penalty reversal logic.

## Regression tests to add/keep

- Initial dashboard for a seeded shared bonus such as `Wuschi füttern` shows it open for both children.
- Completing either child’s instance removes it from both children’s open lists and shows it done for both.
- Ledger for the completing child has exactly one earned transaction.
- Undoing from the sibling’s done card reopens the task for both children.
- Ledger returns to neutral with one earned and one undo transaction.
- Required-task completion on a current/future date still does not book positive coins.

## Admin UI layout pitfall

The “Pflicht- und Bonusaufgabe hinzufügen” form can overlap nearby panels on iPad/desktop if it shares a narrow `.admin-form wide` grid slot with other task panels. Prefer a full-width task-create form with its own internal grid, e.g. `admin-form xwide admin-task-create-form` plus `.task-create-fields`, and wrap to two columns below tablet widths.

## Verification

Run at minimum:

```bash
cd /home/agent/projects/FamilyDashboard/backend && pytest tests/test_tasks.py -q
cd /home/agent/projects/FamilyDashboard/backend && pytest -q
cd /home/agent/projects/FamilyDashboard/frontend && npm run build
cd /home/agent/projects/FamilyDashboard && docker compose up -d --build
curl -fsS http://localhost:8000/api/health
curl -I http://localhost:5173
```

Keep production DB guardrails: use the test DB fixture, never `docker compose down -v`, and compare production row counts when tests/deploy touch persistence-sensitive code.
