- 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]>
132 lines
4.0 KiB
Python
132 lines
4.0 KiB
Python
"""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()
|