Neue Stammdaten-Tabelle nummernschema (Migration 0032): Präfix + Stellenzahl einmal je Objekttyp festlegen statt bei jeder Objekt-Anlage manuell einzutippen (Fehlerquelle - Tippfehler, uneinheitliche Schreibweise, falsches Präfix für den Typ). GET /objekte/naechster-code akzeptiert jetzt objekttyp_id als Alternative zu praefix; ohne konfiguriertes Schema bleibt der bisherige manuelle Präfix-Weg nutzbar (Rückwärtskompatibilität). Admin-UI: Nummernschema-Pflege direkt in der Objekttyp-Verwaltung (ObjekttypSection). ObjektAnlegenFormular versucht zuerst das Schema des gewählten Objekttyps, fällt bei 404 auf manuelles Präfix zurück. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
124 lines
4.9 KiB
Python
124 lines
4.9 KiB
Python
import enum
|
|
|
|
from sqlalchemy import Boolean, ForeignKey, Integer, String, Text, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import ENUM as PgEnum
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class MaterialTyp(str, enum.Enum):
|
|
standard = "standard"
|
|
ablauf_charge = "ablauf_charge"
|
|
geraet_sn = "geraet_sn"
|
|
|
|
|
|
materialtyp_pg = PgEnum(MaterialTyp, name="materialtyp", create_type=False)
|
|
|
|
|
|
class Bereich(Base):
|
|
__tablename__ = "bereich"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
beschreibung: Mapped[str | None] = mapped_column(Text)
|
|
|
|
|
|
class Kategorie(Base):
|
|
__tablename__ = "kategorie"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
bereich_id: Mapped[int] = mapped_column(ForeignKey("bereich.id"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
ueberkategorie_id: Mapped[int | None] = mapped_column(ForeignKey("kategorie.id"))
|
|
|
|
|
|
class Standort(Base):
|
|
__tablename__ = "standort"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
adresse: Mapped[str | None] = mapped_column(Text)
|
|
|
|
|
|
class Objekttyp(Base):
|
|
__tablename__ = "objekttyp"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
bereich_id: Mapped[int] = mapped_column(ForeignKey("bereich.id"), nullable=False)
|
|
kategorie_id: Mapped[int | None] = mapped_column(ForeignKey("kategorie.id"))
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
# Karte 11 Nachtrag: nur Objekte dieses Typs dürfen als Fahrzeug (Objekt.
|
|
# fahrzeug_id) zugeordnet werden - grenzt die Fahrzeug-Dropdowns serverseitig
|
|
# ein, ohne einen eigenen Fahrzeug-Objekttyp fachlich zu erzwingen.
|
|
ist_zugfahrzeug: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
|
|
|
|
|
class Nummernschema(Base):
|
|
"""IDENT-003: statt bei jeder Objekt-Anlage das Präfix manuell einzutippen
|
|
(Fehlerquelle - Tippfehler, uneinheitliche Groß-/Kleinschreibung, falsches
|
|
Präfix für den Objekttyp) legt der Admin je Objekttyp einmal Präfix +
|
|
Stellenzahl fest. `naechster_freier_code` schlägt darauf aufbauend den
|
|
nächsten Code vor (PRAEFIX-NNN...), wie bisher, nur nicht mehr frei
|
|
eingebbar. Ein Objekttyp OHNE Schema kann weiterhin mit explizitem Präfix
|
|
angelegt werden (Rückwärtskompatibilität, kein Zwang zur Migration
|
|
bestehender Objekte)."""
|
|
|
|
__tablename__ = "nummernschema"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
objekttyp_id: Mapped[int] = mapped_column(ForeignKey("objekttyp.id"), unique=True, nullable=False)
|
|
praefix: Mapped[str] = mapped_column(String, nullable=False)
|
|
stellenzahl: Mapped[int] = mapped_column(Integer, nullable=False, default=5)
|
|
|
|
|
|
class Fach(Base):
|
|
"""Nutzer-Vorgabe: feste Fächer-Liste je Objekttyp, damit beim Anlegen einer
|
|
Vorlagenposition nicht jedes Mal Freitext getippt werden muss. `sortierung`
|
|
steuert die Anzeigereihenfolge (z. B. von oben nach unten im Rucksack)."""
|
|
|
|
__tablename__ = "fach"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
objekttyp_id: Mapped[int] = mapped_column(ForeignKey("objekttyp.id"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
sortierung: Mapped[int] = mapped_column(default=0)
|
|
|
|
|
|
class Hersteller(Base):
|
|
"""IDENT-005: normalisierte Hersteller-Stammdaten statt Freitext - macht
|
|
Geräte/Fahrzeuge herstellerübergreifend auswertbar/filterbar (z.B. "alle
|
|
Weinmann-Geräte prüfpflichtig"). Ergänzt Material.hersteller (Freitext,
|
|
bleibt unverändert), betrifft hier gezielt Geräteinstanzen mit
|
|
Seriennummer (IDENT-004)."""
|
|
|
|
__tablename__ = "hersteller"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
|
|
|
|
class Modell(Base):
|
|
__tablename__ = "modell"
|
|
__table_args__ = (UniqueConstraint("hersteller_id", "name"),)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
hersteller_id: Mapped[int] = mapped_column(ForeignKey("hersteller.id"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
|
|
|
|
class Material(Base):
|
|
__tablename__ = "material"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
artikelnummer: Mapped[str | None] = mapped_column(String)
|
|
einheit: Mapped[str] = mapped_column(String, nullable=False)
|
|
materialtyp: Mapped[MaterialTyp] = mapped_column(materialtyp_pg, nullable=False)
|
|
kategorie_id: Mapped[int | None] = mapped_column(ForeignKey("kategorie.id"))
|
|
hersteller: Mapped[str | None] = mapped_column(String)
|
|
beschreibung: Mapped[str | None] = mapped_column(Text)
|
|
code: Mapped[str | None] = mapped_column(String, unique=True)
|
|
warnzeitraum_tage: Mapped[int | None] = mapped_column()
|
|
aktiv: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|