Backend: Mindestbestand je Lagerort für Produkte und Gruppen
Zusaetzlich zum globalen Mindestbestand: je Produkt und je Gruppe laesst sich pro
Lagerort ein Mindestbestand (in Artikeleinheiten) hinterlegen.
- Neue Tabellen product_location_min_stock / group_location_min_stock.
- PUT /products/{id}/location-min-stock und /groups/{id}/location-min-stock
ersetzen die Eintraege; Produkt-/Gruppen-Ausgabe liefert sie mit.
- Neue Einkaufsliste GET /shopping-list/by-location: Bedarfe je Ort (Produkte +
Gruppen), Bestand-am-Ort gegen Mindestbestand-am-Ort.
- Helfer location_stock_base (Bestand je Ort). 4 neue Tests, Suite 144 gruen.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
62
backend/tests/test_location_needs.py
Normal file
62
backend/tests/test_location_needs.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""Bedarfe (Mindestbestände) je Lagerort und die Einkaufsliste je Ort."""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models import (
|
||||
BaseUnit,
|
||||
Location,
|
||||
Lot,
|
||||
Product,
|
||||
ProductLocationMinStock,
|
||||
Role,
|
||||
User,
|
||||
)
|
||||
from app.routers.views import shopping_list_by_location
|
||||
|
||||
|
||||
@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_bedarf_je_lagerort(db, user):
|
||||
# package_size=1 -> Artikeleinheit == Basiseinheit, macht die Rechnung klar.
|
||||
p = Product(name="Kaffee", base_unit=BaseUnit.gram, package_size=1)
|
||||
db.add(p)
|
||||
db.flush()
|
||||
zuhause = Location(name="Zuhause")
|
||||
ferien = Location(name="Ferienhaus")
|
||||
db.add_all([zuhause, ferien])
|
||||
db.flush()
|
||||
|
||||
# 1 Stück zuhause, nichts im Ferienhaus.
|
||||
db.add(Lot(product_id=p.id, quantity=1, location_id=zuhause.id))
|
||||
db.add(ProductLocationMinStock(product_id=p.id, location_id=zuhause.id, min_stock=3))
|
||||
db.add(ProductLocationMinStock(product_id=p.id, location_id=ferien.id, min_stock=2))
|
||||
db.commit()
|
||||
|
||||
needs = shopping_list_by_location(db=db, _=user)
|
||||
nach_ort = {n.location_name: n for n in needs}
|
||||
|
||||
assert set(nach_ort) == {"Zuhause", "Ferienhaus"}
|
||||
assert nach_ort["Zuhause"].products[0].deficit == 2 # 3 - 1
|
||||
assert nach_ort["Ferienhaus"].products[0].deficit == 2 # 2 - 0
|
||||
|
||||
|
||||
def test_gedeckter_ort_erscheint_nicht(db, user):
|
||||
p = Product(name="Reis", base_unit=BaseUnit.gram, package_size=1)
|
||||
db.add(p)
|
||||
db.flush()
|
||||
zuhause = Location(name="Zuhause")
|
||||
db.add(zuhause)
|
||||
db.flush()
|
||||
db.add(Lot(product_id=p.id, quantity=5, location_id=zuhause.id))
|
||||
db.add(ProductLocationMinStock(product_id=p.id, location_id=zuhause.id, min_stock=3))
|
||||
db.commit()
|
||||
|
||||
# Bestand (5) >= Mindestbestand (3) -> kein Bedarf, kein Eintrag.
|
||||
assert shopping_list_by_location(db=db, _=user) == []
|
||||
Reference in New Issue
Block a user