Mindestbestaende: Bestand je Lagerort anzeigen (nicht nur Gesamt)
Per-Lagerort-Zeilen (Produkt und Gruppe) zeigten '-' beim Bestand, weil die Seite nur den Gesamtbestand kannte. Jetzt liefert LocationMinStockOut.stock den Bestand AN DEM Ort (inkl. Unterorte) mit - bei Produkten in Basiseinheiten, bei Gruppen in der Gruppen-Einheit (analog zu ProductOut.stock/GroupOut.stock). Berechnet ueber location_subtree_stock_base; die Weboberflaeche zeigt ihn wie beim Gesamt-Bestand. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ from ..schemas import (
|
||||
ProductBarcodeOut,
|
||||
)
|
||||
from ..services.conversion import BASE_OF_KIND
|
||||
from ..services.stock import current_stock
|
||||
from ..services.stock import current_stock, location_subtree_stock_base
|
||||
|
||||
router = APIRouter(prefix="/groups", tags=["groups"])
|
||||
|
||||
@@ -77,13 +77,20 @@ def _group_to_out(db: Session, group: Group) -> GroupOut:
|
||||
out.min_stock_unit_name = unit.name
|
||||
out.kind = unit.kind.value
|
||||
else:
|
||||
matching = list(products)
|
||||
out.stock = float(sum(current_stock(db, p.id) for p in products))
|
||||
|
||||
# Bestand je Lagerort (inkl. Unterorte) in derselben Einheit wie out.stock.
|
||||
def _loc_stock(loc_id: str) -> float:
|
||||
total = sum(location_subtree_stock_base(db, p, loc_id) for p in matching)
|
||||
return total / unit.factor if unit is not None else float(total)
|
||||
|
||||
out.location_min_stocks = [
|
||||
LocationMinStockOut(
|
||||
location_id=e.location_id,
|
||||
location_name=e.location.name if e.location else None,
|
||||
min_stock=e.min_stock,
|
||||
stock=_loc_stock(e.location_id),
|
||||
)
|
||||
for e in sorted(group.location_min_stocks, key=lambda x: x.id)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user