fix(objekt): Fahrzeug-Zuordnung als 1:n statt n:m (fachliche Korrektur)
Nutzer-Korrektur: "Ein Objekt gehört immer nur zu genau einem Fahrzeug"
- Spalte gezogen_von_objekt_id -> fahrzeug_id (Rename-Migration 0010)
- Zuvor begonnener n:m-Ansatz (objekt_kopplung Tabelle/Endpoints/Panel)
wieder entfernt, da fachlich falsch
- PATCH /objekte/{id} prüft Existenz + direkten Zyklus (A<->B)
- Frontend: einfache Single-Select "Fahrzeug zuordnen" statt Kopplungs-Panel
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
This commit is contained in:
@@ -300,23 +300,25 @@ async def test_objektposition_label_pdf_ohne_code_ist_404(
|
||||
assert mit_code.content.startswith(b"%PDF")
|
||||
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_anhaenger_kopplung_bei_anlage_und_nachtraeglich(
|
||||
async def test_fahrzeug_zuordnung_bei_anlage_und_nachtraeglich(
|
||||
client, db_session, objekttyp_factory, standort_factory, admin_user
|
||||
):
|
||||
"""Nutzer-Vorgabe: Fahrzeug/Anhänger beide als eigenständige Objekte möglich,
|
||||
optional per gezogen_von_objekt_id gekoppelt."""
|
||||
objekttyp = await objekttyp_factory("Fahrzeug/Anhänger")
|
||||
standort = await standort_factory("Wache-Kopplung")
|
||||
"""Nutzer-Vorgabe: jedes Objekt (Rucksack/Gerät/Anhänger) gehört zu jedem
|
||||
Zeitpunkt höchstens einem Fahrzeug (1:n) - Fahrzeug selbst ist einfach ein
|
||||
Objekt ohne eigene fahrzeug_id."""
|
||||
objekttyp = await objekttyp_factory("Fahrzeug/Zuordnung")
|
||||
standort = await standort_factory("Wache-Zuordnung")
|
||||
vorlage = await erstelle_vorlage(
|
||||
db_session, objekttyp_id=objekttyp.id, name="Kopplung Standard", positionen=[]
|
||||
db_session, objekttyp_id=objekttyp.id, name="Zuordnung Standard", positionen=[]
|
||||
)
|
||||
token = await login(client, "admin1")
|
||||
|
||||
fahrzeug = await client.post(
|
||||
"/api/v1/objekte",
|
||||
json={
|
||||
"code": "FZ-K1",
|
||||
"code": "ZO-FZ",
|
||||
"name": "Zugfahrzeug",
|
||||
"objekttyp_id": objekttyp.id,
|
||||
"vorlage_id": vorlage.id,
|
||||
@@ -325,29 +327,29 @@ async def test_anhaenger_kopplung_bei_anlage_und_nachtraeglich(
|
||||
headers=auth_header(token),
|
||||
)
|
||||
fahrzeug_id = fahrzeug.json()["id"]
|
||||
assert fahrzeug.json()["gezogen_von_objekt_id"] is None
|
||||
assert fahrzeug.json()["fahrzeug_id"] is None
|
||||
|
||||
anhaenger = await client.post(
|
||||
zugeordnet = await client.post(
|
||||
"/api/v1/objekte",
|
||||
json={
|
||||
"code": "AH-K1",
|
||||
"name": "Anhänger",
|
||||
"code": "ZO-RK",
|
||||
"name": "Rucksack",
|
||||
"objekttyp_id": objekttyp.id,
|
||||
"vorlage_id": vorlage.id,
|
||||
"standort_id": standort.id,
|
||||
"gezogen_von_objekt_id": fahrzeug_id,
|
||||
"fahrzeug_id": fahrzeug_id,
|
||||
},
|
||||
headers=auth_header(token),
|
||||
)
|
||||
assert anhaenger.status_code == 201
|
||||
assert anhaenger.json()["gezogen_von_objekt_id"] == fahrzeug_id
|
||||
assert zugeordnet.status_code == 201
|
||||
assert zugeordnet.json()["fahrzeug_id"] == fahrzeug_id
|
||||
|
||||
# unabhängiger Anhänger, erst nachträglich gekoppelt
|
||||
# unabhängiges Objekt, erst nachträglich zugeordnet
|
||||
unabhaengig = await client.post(
|
||||
"/api/v1/objekte",
|
||||
json={
|
||||
"code": "AH-K2",
|
||||
"name": "Anhänger 2",
|
||||
"code": "ZO-GR",
|
||||
"name": "Gerät",
|
||||
"objekttyp_id": objekttyp.id,
|
||||
"vorlage_id": vorlage.id,
|
||||
"standort_id": standort.id,
|
||||
@@ -355,39 +357,35 @@ async def test_anhaenger_kopplung_bei_anlage_und_nachtraeglich(
|
||||
headers=auth_header(token),
|
||||
)
|
||||
unabhaengig_id = unabhaengig.json()["id"]
|
||||
assert unabhaengig.json()["gezogen_von_objekt_id"] is None
|
||||
assert unabhaengig.json()["fahrzeug_id"] is None
|
||||
|
||||
geaendert = await client.patch(
|
||||
f"/api/v1/objekte/{unabhaengig_id}",
|
||||
json={"gezogen_von_objekt_id": fahrzeug_id},
|
||||
headers=auth_header(token),
|
||||
f"/api/v1/objekte/{unabhaengig_id}", json={"fahrzeug_id": fahrzeug_id}, headers=auth_header(token)
|
||||
)
|
||||
assert geaendert.status_code == 200
|
||||
assert geaendert.json()["gezogen_von_objekt_id"] == fahrzeug_id
|
||||
assert geaendert.json()["fahrzeug_id"] == fahrzeug_id
|
||||
|
||||
geloest = await client.patch(
|
||||
f"/api/v1/objekte/{unabhaengig_id}",
|
||||
json={"gezogen_von_objekt_id": None},
|
||||
headers=auth_header(token),
|
||||
f"/api/v1/objekte/{unabhaengig_id}", json={"fahrzeug_id": None}, headers=auth_header(token)
|
||||
)
|
||||
assert geloest.json()["gezogen_von_objekt_id"] is None
|
||||
assert geloest.json()["fahrzeug_id"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_anhaenger_kopplung_lehnt_selbstbezug_und_zyklus_ab(
|
||||
async def test_fahrzeug_zuordnung_lehnt_selbstbezug_und_zyklus_ab(
|
||||
client, db_session, objekttyp_factory, standort_factory, admin_user
|
||||
):
|
||||
objekttyp = await objekttyp_factory("Fahrzeug/Anhänger Zyklus")
|
||||
standort = await standort_factory("Wache-Zyklus")
|
||||
objekttyp = await objekttyp_factory("Fahrzeug/Zuordnung Zyklus")
|
||||
standort = await standort_factory("Wache-Zyklus-Zuordnung")
|
||||
vorlage = await erstelle_vorlage(
|
||||
db_session, objekttyp_id=objekttyp.id, name="Zyklus Standard", positionen=[]
|
||||
db_session, objekttyp_id=objekttyp.id, name="Zyklus-Zuordnung Standard", positionen=[]
|
||||
)
|
||||
token = await login(client, "admin1")
|
||||
|
||||
a = await client.post(
|
||||
"/api/v1/objekte",
|
||||
json={
|
||||
"code": "ZY-A",
|
||||
"code": "ZYO-A",
|
||||
"name": "Objekt A",
|
||||
"objekttyp_id": objekttyp.id,
|
||||
"vorlage_id": vorlage.id,
|
||||
@@ -397,35 +395,32 @@ async def test_anhaenger_kopplung_lehnt_selbstbezug_und_zyklus_ab(
|
||||
)
|
||||
a_id = a.json()["id"]
|
||||
|
||||
# Selbstbezug: A zieht sich selbst
|
||||
selbstbezug = await client.patch(
|
||||
f"/api/v1/objekte/{a_id}", json={"gezogen_von_objekt_id": a_id}, headers=auth_header(token)
|
||||
f"/api/v1/objekte/{a_id}", json={"fahrzeug_id": a_id}, headers=auth_header(token)
|
||||
)
|
||||
assert selbstbezug.status_code == 409
|
||||
|
||||
# nicht existierendes Zielobjekt
|
||||
ungueltig = await client.patch(
|
||||
f"/api/v1/objekte/{a_id}", json={"gezogen_von_objekt_id": 999999}, headers=auth_header(token)
|
||||
f"/api/v1/objekte/{a_id}", json={"fahrzeug_id": 999999}, headers=auth_header(token)
|
||||
)
|
||||
assert ungueltig.status_code == 404
|
||||
|
||||
b = await client.post(
|
||||
"/api/v1/objekte",
|
||||
json={
|
||||
"code": "ZY-B",
|
||||
"code": "ZYO-B",
|
||||
"name": "Objekt B",
|
||||
"objekttyp_id": objekttyp.id,
|
||||
"vorlage_id": vorlage.id,
|
||||
"standort_id": standort.id,
|
||||
"gezogen_von_objekt_id": a_id,
|
||||
"fahrzeug_id": a_id,
|
||||
},
|
||||
headers=auth_header(token),
|
||||
)
|
||||
b_id = b.json()["id"]
|
||||
assert b.json()["gezogen_von_objekt_id"] == a_id
|
||||
assert b.json()["fahrzeug_id"] == a_id
|
||||
|
||||
# Zyklus: A soll jetzt von B gezogen werden (B wird bereits von A gezogen)
|
||||
zyklus = await client.patch(
|
||||
f"/api/v1/objekte/{a_id}", json={"gezogen_von_objekt_id": b_id}, headers=auth_header(token)
|
||||
f"/api/v1/objekte/{a_id}", json={"fahrzeug_id": b_id}, headers=auth_header(token)
|
||||
)
|
||||
assert zyklus.status_code == 409
|
||||
|
||||
Reference in New Issue
Block a user