Nachschlagen: Lagerort-QR zeigt alle Artikel an diesem Ort

Neuer Endpunkt GET /location/{code} liefert alle Artikel an einem Lagerort inkl. der Unterorte (Lot-Bestaende und Einzelstuecke), sortiert nach Name mit Menge in Artikeleinheiten. In der App loest der /l/-QR beim Nachschlagen jetzt diese Liste auf; ein Tipp auf einen Eintrag oeffnet den Artikel.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-27 13:10:29 +02:00
parent 4607e3a6a8
commit 21ab0a825a
6 changed files with 258 additions and 5 deletions

View File

@@ -0,0 +1,64 @@
"""Lagerort-Inhalt: was liegt an einem Ort inklusive der Unterorte?"""
import pytest
from fastapi import HTTPException
from app.models import BaseUnit, Item, Location, Lot, Product, Role, User
from app.routers.views import location_contents
@pytest.fixture()
def user(db):
person = User(username="tester", password_hash="x", role=Role.admin)
db.add(person)
db.commit()
db.refresh(person)
return person
def test_zeigt_artikel_inkl_unterorten(db, user):
haus = Location(name="Hedingen")
db.add(haus)
db.flush()
keller = Location(name="Keller", parent_id=haus.id)
db.add(keller)
db.flush()
# package_size=1 -> Artikeleinheit == Basiseinheit, macht die Menge klar.
kaffee = Product(name="Kaffee", base_unit=BaseUnit.gram, package_size=1)
bohrer = Product(name="Bohrer", base_unit=BaseUnit.piece, package_size=1, individual=True)
db.add_all([kaffee, bohrer])
db.flush()
# Lot im Unterort (Keller), Einzelstück direkt in Hedingen.
db.add(Lot(product_id=kaffee.id, quantity=3, location_id=keller.id))
db.add(Item(uid="AAAA111111", product_id=bohrer.id, location_id=haus.id))
db.commit()
inhalt = location_contents(code=haus.id, db=db, _=user)
assert inhalt.location_name == "Hedingen"
nach_name = {e.name: e for e in inhalt.products}
assert set(nach_name) == {"Kaffee", "Bohrer"} # Bestand im Unterort zaehlt mit
assert nach_name["Kaffee"].stock == 3
assert nach_name["Bohrer"].stock == 1
assert nach_name["Bohrer"].individual is True
def test_nur_der_gescannte_teilbaum(db, user):
a = Location(name="Ort A")
b = Location(name="Ort B")
db.add_all([a, b])
db.flush()
p = Product(name="Reis", base_unit=BaseUnit.gram, package_size=1)
db.add(p)
db.flush()
db.add(Lot(product_id=p.id, quantity=2, location_id=b.id))
db.commit()
# In A liegt nichts der Bestand von B darf nicht auftauchen.
assert location_contents(code=a.id, db=db, _=user).products == []
def test_unbekannter_ort_404(db, user):
with pytest.raises(HTTPException) as ex:
location_contents(code="ZZZZZZZZZZ", db=db, _=user)
assert ex.value.status_code == 404