Let a day removed from a period stay removed

Taking one day out of a period the planner placed did nothing that
lasted: the period still asked for a full week, so the next sync put the
day straight back. The option was disabled rather than lying about it.

A removed day is now recorded as its own thing — no leave for this
parent, this child, this date — and the planner honours it on every
later sync. It is kept apart from the working-day overrides, which
answer a different question about the calendar rather than about the
plan.

The day belongs to the parent whose band was clicked, so removing one
parent's day leaves their partner's alone; where both parents were to be
off on one funding arrangement, the partner is simply funded on their
own instead. A removed day shortens what the period is asking for rather
than counting as a day the plan failed to find, so the advice about
closing a shortfall does not start arguing for a day nobody wants.

Nothing is removed without a way back: the toast undoes it, and the day
itself is marked in the calendar and offers to restore.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ei7gCZzdd751uZtPzb1Pep
This commit is contained in:
2026-09-19 16:05:17 +02:00
parent 6d92b87bf3
commit 8cfb9c82c6
39 changed files with 2362 additions and 31 deletions
@@ -0,0 +1,133 @@
"""SQLite implementation of PlannedDayExclusionRepository.
Follows the SQLiteDayOverrideRepository reference shape: map rows <-> entities
explicitly in `_row_to_entity`, always parameterize queries, raise
NotFoundError from update/delete when the row is missing.
"""
from datetime import date, datetime
from uuid import UUID
import aiosqlite
from app.db.connection import commit
from app.entities.planned_day_exclusion import PlannedDayExclusion
from app.repositories.filter_validator import validate_filters
from app.repositories.planned_day_exclusion_repository import PlannedDayExclusionRepository
from app.utils.errors import NotFoundError
class SQLitePlannedDayExclusionRepository(PlannedDayExclusionRepository):
def __init__(self, connection: aiosqlite.Connection) -> None:
self._conn = connection
@staticmethod
def _row_to_entity(row: aiosqlite.Row) -> PlannedDayExclusion:
return PlannedDayExclusion(
id=UUID(row["id"]),
workspace_id=UUID(row["workspace_id"]),
child_id=UUID(row["child_id"]),
parent_personal_data_uuid=UUID(row["parent_personal_data_uuid"]),
date=date.fromisoformat(row["date"]),
created_at=datetime.fromisoformat(row["created_at"]),
updated_at=datetime.fromisoformat(row["updated_at"]),
)
async def create(self, item: PlannedDayExclusion) -> PlannedDayExclusion:
now = datetime.now()
item.created_at = item.created_at or now
item.updated_at = now
await self._conn.execute(
"""
INSERT INTO planned_day_exclusion
(id, workspace_id, child_id, parent_personal_data_uuid, date,
created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(
str(item.id),
str(item.workspace_id),
str(item.child_id),
str(item.parent_personal_data_uuid),
item.date.isoformat(),
item.created_at.isoformat(),
item.updated_at.isoformat(),
),
)
await commit(self._conn)
return item
async def get_by_id(self, id: UUID) -> PlannedDayExclusion | None:
cursor = await self._conn.execute(
"SELECT * FROM planned_day_exclusion WHERE id = ?", (str(id),)
)
row = await cursor.fetchone()
return self._row_to_entity(row) if row else None
async def get_by_natural_key(
self,
workspace_id: UUID,
child_id: UUID,
parent_personal_data_uuid: UUID,
day: date,
) -> PlannedDayExclusion | None:
cursor = await self._conn.execute(
"""
SELECT * FROM planned_day_exclusion
WHERE workspace_id = ? AND child_id = ?
AND parent_personal_data_uuid = ? AND date = ?
""",
(
str(workspace_id),
str(child_id),
str(parent_personal_data_uuid),
day.isoformat(),
),
)
row = await cursor.fetchone()
return self._row_to_entity(row) if row else None
async def update(self, id: UUID, item: PlannedDayExclusion) -> PlannedDayExclusion:
"""Only `date` is mutable; the rest of the row IS its identity.
Kept for the `Repository[T]` contract — the service never calls it
(an exclusion is created or deleted, never edited in place).
"""
item.updated_at = datetime.now()
cursor = await self._conn.execute(
"UPDATE planned_day_exclusion SET date = ?, updated_at = ? WHERE id = ?",
(item.date.isoformat(), item.updated_at.isoformat(), str(id)),
)
await commit(self._conn)
if cursor.rowcount == 0:
raise NotFoundError(f"PlannedDayExclusion {id} not found")
refreshed = await self.get_by_id(id)
assert refreshed is not None # just updated
return refreshed
async def delete(self, id: UUID) -> None:
cursor = await self._conn.execute(
"DELETE FROM planned_day_exclusion WHERE id = ?", (str(id),)
)
await commit(self._conn)
if cursor.rowcount == 0:
raise NotFoundError(f"PlannedDayExclusion {id} not found")
async def list(self, **filters: object) -> list[PlannedDayExclusion]:
validate_filters(filters, {"workspace_id", "child_id", "parent_personal_data_uuid"})
clauses: list[str] = []
params: list[object] = []
for column in ("workspace_id", "child_id", "parent_personal_data_uuid"):
if column in filters and filters[column] is not None:
value = filters[column]
clauses.append(f"{column} = ?")
params.append(str(value) if isinstance(value, UUID) else value)
where = f" WHERE {' AND '.join(clauses)}" if clauses else ""
cursor = await self._conn.execute(
f"SELECT * FROM planned_day_exclusion{where} ORDER BY date ASC", params
)
rows = await cursor.fetchall()
return [self._row_to_entity(row) for row in rows]
async def list_by_workspace(self, workspace_id: UUID) -> list[PlannedDayExclusion]:
return await self.list(workspace_id=workspace_id)