Backend: gleiche Chargen (Artikel+MHD+Ort) werden zusammengefasst
Nach dem Umlagern/Aufteilen entstanden Dubletten: zwei Chargen desselben Artikels mit gleichem MHD am gleichen Lagerort, obwohl das fuer den Nutzer eine Charge ist. Neu: consolidate_lot_group fasst solche Chargen zusammen (Mengen addieren, Bewegungen auf die aeltere Charge umhaengen, Rest loeschen) - aufgerufen nach split, bulk-location und update_lot. Bestand und Historie bleiben unveraendert. Beim Start raeumt consolidate_duplicate_lots einmalig bestehende Dubletten auf. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,7 @@ from ..services.stock import (
|
||||
check_in,
|
||||
check_out,
|
||||
check_out_lot,
|
||||
consolidate_lot_group,
|
||||
current_stock,
|
||||
object_add,
|
||||
object_relocate,
|
||||
@@ -292,6 +293,16 @@ def bulk_lot_location(
|
||||
.filter(Lot.id.in_(payload.lot_ids))
|
||||
.update({Lot.location_id: payload.location_id}, synchronize_session=False)
|
||||
)
|
||||
db.flush()
|
||||
# Am Zielort entstandene Dubletten (gleicher Artikel + MHD) zusammenfassen.
|
||||
gruppen = (
|
||||
db.query(Lot.product_id, Lot.best_before, Lot.best_before_precision)
|
||||
.filter(Lot.id.in_(payload.lot_ids))
|
||||
.distinct()
|
||||
.all()
|
||||
)
|
||||
for product_id, best_before, precision in gruppen:
|
||||
consolidate_lot_group(db, product_id, best_before, precision, payload.location_id)
|
||||
db.commit()
|
||||
return n
|
||||
|
||||
@@ -335,9 +346,14 @@ def split_lot(
|
||||
location_id=payload.location_id,
|
||||
)
|
||||
db.add(neu)
|
||||
db.flush()
|
||||
# Liegt am Zielort schon eine Charge mit gleichem MHD, verschmelzen beide.
|
||||
survivor = consolidate_lot_group(
|
||||
db, lot.product_id, neu.best_before, neu.best_before_precision, payload.location_id
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(neu)
|
||||
return neu
|
||||
db.refresh(survivor)
|
||||
return survivor
|
||||
|
||||
|
||||
@router.patch("/lots/{lot_id}", response_model=LotOut)
|
||||
@@ -383,9 +399,15 @@ def update_lot(
|
||||
note="Charge korrigiert",
|
||||
)
|
||||
)
|
||||
db.flush()
|
||||
# Ist die Charge durch die Änderung (Lagerort/MHD) zur Dublette einer anderen
|
||||
# geworden, werden beide zusammengefasst.
|
||||
survivor = consolidate_lot_group(
|
||||
db, lot.product_id, lot.best_before, lot.best_before_precision, lot.location_id
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(lot)
|
||||
return lot
|
||||
db.refresh(survivor)
|
||||
return survivor
|
||||
|
||||
|
||||
@router.delete("/lots/{lot_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
Reference in New Issue
Block a user