Free days, vacation forfeiture, and global auto-replanning
Free days (Sat/Sun/red days, subject to DayOverride) can never be vacation, and can only be parental leave when the workspace opts in via take_pl_on_red_days. The allocator already honoured this; the hand-pin path bypassed it entirely. - PlanningService gains optional workspace_repo/day_override_repo deps and _reject_illegal_free_day, enforced in add_planned_day and update. Reuses allocation_service.is_free_day rather than re-deriving it, and no-ops when the deps are unset so existing callers are unaffected. - update_planned_day had no ValidationError handler at all, so a validation failure there 500'd instead of 422'ing. Fixed. - Calendar filters the pin write loop by the day's isFree; the modal explains free days stay off, and that pinning opts a day out of automatic re-planning. Vacation days at risk of forfeiture were computed and sent over the wire but never rendered: an at-risk column with the age-out/over-cap split, and a dashboard key figure. PlanProposal.warnings was likewise parsed but rendered nowhere, for all three kinds. Adds PlanWarningCard in a Risks section above the tips, with parent names resolved and dates formatted. POST /api/plan/sync now fires from the workspace layer on every plan-input change rather than only from Calendar, so a Settings edit or a pinned-day save re-plans day types instead of merely refetching. Overlapping bumps coalesce into one trailing run; a rejection cannot wedge the in-flight guard. eviction_preview was silently dropped by the frontend despite always being on the wire, and is now surfaced through context. Verified: backend 890 passed (91.49% coverage), frontend 1297 passed, ruff/eslint/tsc clean. Browser-checked in Swedish and English. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JVQx4NUvPbJhn6UcvRd2QY
This commit is contained in:
@@ -24,7 +24,7 @@ different range.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from datetime import date, timedelta
|
||||
from typing import Any
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
@@ -37,7 +37,8 @@ from httpx import ASGITransport, AsyncClient
|
||||
from app.config import settings
|
||||
from app.dependencies import get_connection
|
||||
from app.main import app
|
||||
from app.utils.holidays import cached_year_bounds
|
||||
from app.services.allocation_service import is_free_day
|
||||
from app.utils.holidays import cached_year_bounds, get_swedish_holidays
|
||||
|
||||
_PASSWORD = "correct horse battery staple"
|
||||
|
||||
@@ -209,6 +210,26 @@ async def _list_planned_days(
|
||||
return resp.json()
|
||||
|
||||
|
||||
def _next_workday(start: date) -> date:
|
||||
"""The next date at/after `start` that isn't free (weekend/red day).
|
||||
|
||||
Used for probe rows whose exact date doesn't matter except that it must
|
||||
be legal to plan as `vacation` — see
|
||||
`PlanningService._reject_illegal_free_day`. `start` (typically
|
||||
`date.today()`) is otherwise arbitrary and, per this file's own
|
||||
docstring, deliberately never hardcoded.
|
||||
"""
|
||||
d = start
|
||||
year = d.year
|
||||
holidays_map = get_swedish_holidays(year)
|
||||
while is_free_day(d, holidays_map):
|
||||
d += timedelta(days=1)
|
||||
if d.year != year:
|
||||
year = d.year
|
||||
holidays_map = get_swedish_holidays(year)
|
||||
return d
|
||||
|
||||
|
||||
def _paid_days_for_wish(proposal: dict[str, Any], wish_id: str) -> list[dict[str, Any]]:
|
||||
"""Proposed days belonging to `wish_id` that would actually cost a
|
||||
|
||||
@@ -1061,7 +1082,11 @@ class TestPlannedDayIsPinnedRoundTripAndSyncSurvival:
|
||||
"workspace_id": str(ws_id),
|
||||
"child_id": str(child_id),
|
||||
"parent_personal_data_uuid": str(pd_uuid),
|
||||
"date": date.today().isoformat(),
|
||||
# An ad-hoc probe row for the is_pinned round trip below —
|
||||
# the exact date is irrelevant except that it must be legal
|
||||
# to plan as `vacation` (never a free day; see
|
||||
# `PlanningService._reject_illegal_free_day`).
|
||||
"date": _next_workday(date.today()).isoformat(),
|
||||
"day_type": "vacation",
|
||||
"is_dubbeldag": False,
|
||||
"wish_id": wish_id,
|
||||
|
||||
Reference in New Issue
Block a user