Vaihe 1/3: pohjatiedot (palveluyksiköt, palvelut ja työtehtävät)

- Uusi catalog-moduuli: palveluyksikkö → (palvelu) → työtehtävä ilman hintoja.
- Pohjatiedot-sivu /catalog/ pääkäyttäjälle ja johdolle (oikeus catalog.manage):
  lisäys ja muokkaus dialogissa, Siirrä ylös / Siirrä alas, käytöstä poisto ja
  käyttöön otto. Fokus ja aria-live-ilmoitus jokaisen muutoksen jälkeen.
- Rivejä ei poisteta. Käytöstä poistetun yläkohdan alla olevat rivit säilyttävät
  oman tilansa, mutta eivät ole valittavissa. Nimi on yksilöllinen samalla
  tasolla kirjainkoosta riippumatta.
- Työtehtävän voi siirtää saman yksikön toiseen palveluun tai suoraan yksikön alle.
- Luvun 11.1 lista data-migraationa (0002_seed), jos taulut ovat tyhjiä.
- CatalogQueries: work_type_options, active_service_units ja get_work_type
  tehtäviä ja tuntikirjausta varten.
- Import-linter-sopimukset, suomennokset, yksikkö-, integraatio- ja selaintestit.
- Päivitetty CLAUDE.md ja määrittelyn kohta 16.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-29 14:07:41 +02:00
co-authored by Claude Opus 5.5
parent a81c073d6a
commit 679bf57eb4
51 changed files with 2722 additions and 132 deletions
View File
+131
View File
@@ -0,0 +1,131 @@
"""Service units, services and work types (specification 11.1).
Hierarchy: service unit → (service) → work type. Rows are never deleted, only deactivated.
A deactivated row keeps its children's own ``is_active`` flags; the children are just not
selectable while a parent is inactive.
"""
from dataclasses import dataclass, replace
from typing import Self
from apps.catalog.domain.exceptions import ServiceNotInUnit
from apps.catalog.domain.value_objects import CatalogName
@dataclass(frozen=True, slots=True)
class ServiceUnit:
id: int | None
name: CatalogName
is_shared: bool = False # "Kaikille yhteiset": its work types are selectable in every unit
is_active: bool = True
sort_order: int = 0
@classmethod
def register(cls, *, name: CatalogName, sort_order: int) -> Self:
return cls(id=None, name=name, sort_order=sort_order)
@classmethod
def reconstitute(
cls, *, id: int, name: CatalogName, is_shared: bool, is_active: bool, sort_order: int
) -> Self:
return cls(id, name, is_shared, is_active, sort_order)
def rename(self, name: CatalogName) -> Self:
return replace(self, name=name)
def with_active(self, active: bool) -> Self:
return replace(self, is_active=active)
def with_id(self, id: int) -> Self:
return replace(self, id=id)
@dataclass(frozen=True, slots=True)
class Service:
id: int | None
service_unit_id: int
name: CatalogName
is_active: bool = True
sort_order: int = 0
@classmethod
def register(cls, *, service_unit_id: int, name: CatalogName, sort_order: int) -> Self:
return cls(id=None, service_unit_id=service_unit_id, name=name, sort_order=sort_order)
@classmethod
def reconstitute(
cls, *, id: int, service_unit_id: int, name: CatalogName, is_active: bool, sort_order: int
) -> Self:
return cls(id, service_unit_id, name, is_active, sort_order)
def rename(self, name: CatalogName) -> Self:
return replace(self, name=name)
def with_active(self, active: bool) -> Self:
return replace(self, is_active=active)
def with_id(self, id: int) -> Self:
return replace(self, id=id)
@dataclass(frozen=True, slots=True)
class WorkType:
"""A work type sits directly under its service unit (``service_id`` None) or under one
of that unit's services."""
id: int | None
service_unit_id: int
service_id: int | None
name: CatalogName
is_active: bool = True
sort_order: int = 0
@classmethod
def register(
cls,
*,
service_unit_id: int,
service: Service | None,
name: CatalogName,
sort_order: int,
) -> Self:
_check_service(service_unit_id, service)
return cls(
id=None,
service_unit_id=service_unit_id,
service_id=service.id if service else None,
name=name,
sort_order=sort_order,
)
@classmethod
def reconstitute(
cls,
*,
id: int,
service_unit_id: int,
service_id: int | None,
name: CatalogName,
is_active: bool,
sort_order: int,
) -> Self:
return cls(id, service_unit_id, service_id, name, is_active, sort_order)
def move_to(self, service: Service | None, *, sort_order: int) -> Self:
"""Move under another service of the same unit, or directly under the unit."""
_check_service(self.service_unit_id, service)
return replace(self, service_id=service.id if service else None, sort_order=sort_order)
def rename(self, name: CatalogName) -> Self:
return replace(self, name=name)
def with_active(self, active: bool) -> Self:
return replace(self, is_active=active)
def with_id(self, id: int) -> Self:
return replace(self, id=id)
def _check_service(service_unit_id: int, service: Service | None) -> None:
if service is not None and service.service_unit_id != service_unit_id:
raise ServiceNotInUnit()
+47
View File
@@ -0,0 +1,47 @@
from apps.shared.domain.exceptions import DomainError
class InvalidCatalogName(DomainError):
code = "invalid_catalog_name"
field = "name"
class ServiceUnitNameTaken(DomainError):
code = "service_unit_name_taken"
field = "name"
class ServiceNameTaken(DomainError):
code = "service_name_taken"
field = "name"
class WorkTypeNameTaken(DomainError):
code = "work_type_name_taken"
field = "name"
class ServiceUnitNotFound(DomainError):
code = "service_unit_not_found"
class ServiceNotFound(DomainError):
code = "service_not_found"
field = "service"
class WorkTypeNotFound(DomainError):
code = "work_type_not_found"
class ServiceNotInUnit(DomainError):
"""A work type can only belong to a service of its own service unit."""
code = "service_not_in_unit"
field = "service"
class CannotMove(DomainError):
"""The first row cannot move up and the last row cannot move down."""
code = "cannot_move"
+22
View File
@@ -0,0 +1,22 @@
"""Manual ordering of sibling rows with "Move up" / "Move down" buttons (specification 16.3)."""
from collections.abc import Sequence
from enum import StrEnum
from apps.catalog.domain.exceptions import CannotMove
class Direction(StrEnum):
UP = "up"
DOWN = "down"
def move(ids: Sequence[int], item_id: int, direction: Direction) -> list[int]:
"""Return ``ids`` with ``item_id`` swapped with its neighbour in ``direction``."""
order = list(ids)
index = order.index(item_id)
target = index - 1 if direction is Direction.UP else index + 1
if not 0 <= target < len(order):
raise CannotMove()
order[index], order[target] = order[target], order[index]
return order
+55
View File
@@ -0,0 +1,55 @@
from collections.abc import Sequence
from typing import Protocol, Self
from apps.catalog.domain.entities import Service, ServiceUnit, WorkType
from apps.catalog.domain.value_objects import CatalogName
class CatalogItem(Protocol):
"""What service units, services and work types share: activation and ordering."""
@property
def id(self) -> int | None: ...
def with_active(self, active: bool) -> Self: ...
class OrderedRepository[T: CatalogItem](Protocol):
def get(self, item_id: int) -> T | None: ...
def save(self, item: T) -> T: ...
def sibling_ids(self, item: T) -> list[int]:
"""Ids of the rows on the same level as ``item`` (itself included), in order."""
...
def set_order(self, ids: Sequence[int]) -> None:
"""Renumber ``sort_order`` of these rows in the given order."""
...
class ServiceUnitRepository(OrderedRepository[ServiceUnit], Protocol):
def is_name_taken(self, name: CatalogName, *, exclude_id: int | None = None) -> bool: ...
def next_sort_order(self) -> int: ...
class ServiceRepository(OrderedRepository[Service], Protocol):
def is_name_taken(
self, service_unit_id: int, name: CatalogName, *, exclude_id: int | None = None
) -> bool: ...
def next_sort_order(self, service_unit_id: int) -> int: ...
class WorkTypeRepository(OrderedRepository[WorkType], Protocol):
def is_name_taken(
self,
service_unit_id: int,
service_id: int | None,
name: CatalogName,
*,
exclude_id: int | None = None,
) -> bool: ...
def next_sort_order(self, service_unit_id: int, service_id: int | None) -> int: ...
+25
View File
@@ -0,0 +1,25 @@
from dataclasses import dataclass
from apps.catalog.domain.exceptions import InvalidCatalogName
NAME_MAX_LENGTH = 100
@dataclass(frozen=True, slots=True)
class CatalogName:
"""Name of a service unit, service or work type: 1–100 characters, spaces normalized."""
value: str
def __post_init__(self) -> None:
normalized = " ".join(self.value.split())
if not normalized or len(normalized) > NAME_MAX_LENGTH:
raise InvalidCatalogName()
object.__setattr__(self, "value", normalized)
def same_as(self, other: str) -> bool:
"""Names are unique case-insensitively within one level."""
return self.value.casefold() == " ".join(other.split()).casefold()
def __str__(self) -> str:
return self.value