Link planned days to their wish, fix the age-4 cap, drop the planning goal
Three changes that together unblock treating a calendar period as one editable object. Migration 008 adds `planned_leave_day.wish_id` (nullable, ON DELETE SET NULL) so a persisted day knows which `leave_wish` produced it, `is_pinned` to mark a day the user hand-edited, and `leave_wish.target_days` so a period drawn on a calendar need not be a whole number of weeks. Apply-time identity still keys on day_type/is_dubbeldag only, so a wish_id-only difference is a metadata update rather than a collision. The age-4 savable ceiling was applying the per-child figure of 96 to each parent's pool, modelling a two-parent family as able to save 192 days past the child's fourth birthday. `resolve_age4_savable_cap` is now the single place that decides 48 (couple with two parents) versus 96 (everyone else), and both AnalyticsService and the allocator read it. Migration 009 drops `workspace.planning_goal` and `leave_wish.goal_override`. The allocator's tier-3 policy collapses to one rule; `salary_type` still branches, since that reflects what a vacation day actually costs a parent rather than a user preference.
This commit is contained in:
@@ -19,6 +19,7 @@ class Age4ProjectionResponse(BaseModel):
|
||||
projected_left_at_b4: int
|
||||
savable_after_b4: int
|
||||
expiring_at_b4: int
|
||||
savable_cap_at_b4: int
|
||||
|
||||
@classmethod
|
||||
def from_entity(cls, p: Age4Projection) -> "Age4ProjectionResponse":
|
||||
@@ -33,6 +34,7 @@ class Age4ProjectionResponse(BaseModel):
|
||||
projected_left_at_b4=p.projected_left_at_b4,
|
||||
savable_after_b4=p.savable_after_b4,
|
||||
expiring_at_b4=p.expiring_at_b4,
|
||||
savable_cap_at_b4=p.savable_cap_at_b4,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ class LeaveWishCreate(BaseModel):
|
||||
window_end_day: int = Field(ge=1, le=31)
|
||||
|
||||
target_weeks: int = Field(ge=1, le=52)
|
||||
# A calendar-drawn period is not a whole number of weeks. None (default)
|
||||
# falls back to `target_weeks * 7` — see `LeaveWish.target_span_days()`.
|
||||
target_days: int | None = Field(default=None, ge=1)
|
||||
recurrence: str = "once" # 'yearly' | 'once'
|
||||
first_year: int = Field(ge=2000, le=2200)
|
||||
last_year: int | None = Field(default=None, ge=2000, le=2200)
|
||||
@@ -38,8 +41,6 @@ class LeaveWishCreate(BaseModel):
|
||||
parent_mode: str = "either" # 'either' | 'both' | 'specific'
|
||||
parent_personal_data_uuid: UUID | None = None
|
||||
|
||||
goal_override: str | None = None # 'max_time' | 'max_money' | 'balanced' | None
|
||||
|
||||
# PLANNING_ENGINE_SPEC.md §10.1 — 'fixed': window_start_*/window_end_* are the
|
||||
# exact placement (default). 'flexible': the same fields describe the
|
||||
# bounding range the allocator searches within for the best-costing window.
|
||||
@@ -63,6 +64,10 @@ class LeaveWishUpdate(BaseModel):
|
||||
window_end_day: int | None = Field(None, ge=1, le=31)
|
||||
|
||||
target_weeks: int | None = Field(None, ge=1, le=52)
|
||||
# Present + null means "clear it" (fall back to target_weeks); absent
|
||||
# means "leave unchanged" — same convention as the other nullable fields
|
||||
# on this model (see `_clear_*` handling in `LeaveWishService.update`).
|
||||
target_days: int | None = Field(default=None, ge=1)
|
||||
recurrence: str | None = None
|
||||
first_year: int | None = Field(None, ge=2000, le=2200)
|
||||
last_year: int | None = Field(None, ge=2000, le=2200)
|
||||
@@ -71,8 +76,6 @@ class LeaveWishUpdate(BaseModel):
|
||||
parent_mode: str | None = None
|
||||
parent_personal_data_uuid: UUID | None = None
|
||||
|
||||
goal_override: str | None = None
|
||||
|
||||
window_mode: str | None = None # 'fixed' | 'flexible'
|
||||
|
||||
|
||||
@@ -89,6 +92,7 @@ class LeaveWishResponse(BaseModel):
|
||||
window_end_day: int
|
||||
|
||||
target_weeks: int
|
||||
target_days: int | None
|
||||
recurrence: str
|
||||
first_year: int
|
||||
last_year: int | None
|
||||
@@ -97,8 +101,6 @@ class LeaveWishResponse(BaseModel):
|
||||
parent_mode: str
|
||||
parent_personal_data_uuid: UUID | None
|
||||
|
||||
goal_override: str | None
|
||||
|
||||
window_mode: str
|
||||
|
||||
created_at: datetime | None
|
||||
@@ -117,13 +119,13 @@ class LeaveWishResponse(BaseModel):
|
||||
window_end_month=entity.window_end_month,
|
||||
window_end_day=entity.window_end_day,
|
||||
target_weeks=entity.target_weeks,
|
||||
target_days=entity.target_days,
|
||||
recurrence=entity.recurrence,
|
||||
first_year=entity.first_year,
|
||||
last_year=entity.last_year,
|
||||
priority=entity.priority,
|
||||
parent_mode=entity.parent_mode,
|
||||
parent_personal_data_uuid=entity.parent_personal_data_uuid,
|
||||
goal_override=entity.goal_override,
|
||||
window_mode=entity.window_mode,
|
||||
created_at=entity.created_at,
|
||||
updated_at=entity.updated_at,
|
||||
|
||||
@@ -123,6 +123,7 @@ class Age4ProjectionResponse(BaseModel):
|
||||
projected_left_at_b4: int
|
||||
savable_after_b4: int
|
||||
expiring_at_b4: int
|
||||
savable_cap_at_b4: int
|
||||
|
||||
|
||||
class PlanProposalResponse(BaseModel):
|
||||
@@ -218,6 +219,7 @@ class PlanProposalResponse(BaseModel):
|
||||
projected_left_at_b4=p.projected_left_at_b4,
|
||||
savable_after_b4=p.savable_after_b4,
|
||||
expiring_at_b4=p.expiring_at_b4,
|
||||
savable_cap_at_b4=p.savable_cap_at_b4,
|
||||
)
|
||||
for p in proposal.age4_projections
|
||||
],
|
||||
@@ -231,9 +233,12 @@ class PlanProposalResponse(BaseModel):
|
||||
|
||||
class ProposedDayApplyItem(BaseModel):
|
||||
"""One day to persist. Same shape as `ProposedDayResponse` minus the
|
||||
explain-only `wish_id`/`reason` (harmless if a caller sends them anyway —
|
||||
a frontend can hand back `ProposedDayResponse` entries from `/propose`
|
||||
verbatim; extra fields are ignored).
|
||||
explain-only `reason` (harmless if a caller sends it anyway — a frontend
|
||||
can hand back `ProposedDayResponse` entries from `/propose` verbatim;
|
||||
extra fields are ignored). `wish_id` DOES carry persistence meaning here
|
||||
(unlike `reason`): it links the persisted row back to the wish that
|
||||
produced it, so a client handing back a `/propose` day verbatim gets that
|
||||
attribution persisted for free.
|
||||
|
||||
`day_type` additionally accepts 'free' (an automatic weekend/red-day
|
||||
entry from a proposal) purely so a client doesn't have to filter those
|
||||
@@ -246,6 +251,8 @@ class ProposedDayApplyItem(BaseModel):
|
||||
child_id: UUID
|
||||
day_type: str = Field(pattern="^(sjukpenning|lagsta|vacation|free)$")
|
||||
is_dubbeldag: bool = False
|
||||
wish_id: UUID | None = None
|
||||
is_pinned: bool = False
|
||||
|
||||
def to_domain(self) -> ProposedDayInput:
|
||||
return ProposedDayInput(
|
||||
@@ -254,6 +261,8 @@ class ProposedDayApplyItem(BaseModel):
|
||||
child_id=self.child_id,
|
||||
day_type=self.day_type,
|
||||
is_dubbeldag=self.is_dubbeldag,
|
||||
wish_id=self.wish_id,
|
||||
is_pinned=self.is_pinned,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ class PlannedLeaveDayCreate(BaseModel):
|
||||
date: date
|
||||
day_type: str = Field(pattern="^(sjukpenning|lagsta|vacation)$")
|
||||
is_dubbeldag: bool = False
|
||||
# Which `LeaveWish` produced this day; None = ad-hoc.
|
||||
wish_id: UUID | None = None
|
||||
is_pinned: bool = False
|
||||
|
||||
|
||||
class PlannedLeaveDayUpdate(BaseModel):
|
||||
@@ -26,6 +29,8 @@ class PlannedLeaveDayUpdate(BaseModel):
|
||||
|
||||
day_type: str | None = Field(None, pattern="^(sjukpenning|lagsta|vacation)$")
|
||||
is_dubbeldag: bool | None = None
|
||||
wish_id: UUID | None = None
|
||||
is_pinned: bool | None = None
|
||||
|
||||
|
||||
class PlannedLeaveDayResponse(BaseModel):
|
||||
@@ -36,6 +41,8 @@ class PlannedLeaveDayResponse(BaseModel):
|
||||
date: date
|
||||
day_type: str
|
||||
is_dubbeldag: bool
|
||||
wish_id: UUID | None
|
||||
is_pinned: bool
|
||||
created_at: datetime | None
|
||||
updated_at: datetime | None
|
||||
|
||||
@@ -49,6 +56,8 @@ class PlannedLeaveDayResponse(BaseModel):
|
||||
date=entity.date,
|
||||
day_type=entity.day_type,
|
||||
is_dubbeldag=entity.is_dubbeldag,
|
||||
wish_id=entity.wish_id,
|
||||
is_pinned=entity.is_pinned,
|
||||
created_at=entity.created_at,
|
||||
updated_at=entity.updated_at,
|
||||
)
|
||||
|
||||
@@ -15,14 +15,12 @@ class WorkspaceCreate(BaseModel):
|
||||
|
||||
class WorkspaceUpdate(BaseModel):
|
||||
name: str | None = Field(default=None, min_length=1, max_length=100)
|
||||
planning_goal: str | None = None
|
||||
planning_mode: str | None = None
|
||||
|
||||
|
||||
class WorkspaceResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
planning_goal: str
|
||||
planning_mode: str
|
||||
created_at: datetime | None
|
||||
|
||||
@@ -31,7 +29,6 @@ class WorkspaceResponse(BaseModel):
|
||||
return cls(
|
||||
id=ws.id,
|
||||
name=ws.name,
|
||||
planning_goal=ws.planning_goal,
|
||||
planning_mode=ws.planning_mode,
|
||||
created_at=ws.created_at,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user