GS1 scanning and workflow improvements
This commit is contained in:
+35
-1
@@ -1670,7 +1670,41 @@ def create_variant_batch(variant_id: int, payload: BatchCreate, db: Session = De
|
||||
.first()
|
||||
)
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="Batch number already exists for this variant")
|
||||
if existing.expiry_date != payload.expiry_date:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Batch number already exists for this variant with a different expiry date",
|
||||
)
|
||||
|
||||
# Same batch number and expiry — restock the existing batch
|
||||
existing.quantity += batch_quantity
|
||||
if existing.received_pack_id == resolved["pack_id"]:
|
||||
existing.received_pack_count = (existing.received_pack_count or 0) + resolved["pack_count"]
|
||||
if payload.notes:
|
||||
existing.notes = (existing.notes + "\n" + payload.notes) if existing.notes else payload.notes
|
||||
recompute_batch_pack_state(existing)
|
||||
variant.quantity += batch_quantity
|
||||
|
||||
write_audit_log(
|
||||
db,
|
||||
action="batch.restock",
|
||||
entity_type="batch",
|
||||
entity_id=existing.id,
|
||||
actor=current_user,
|
||||
details={
|
||||
"variant_id": variant_id,
|
||||
"batch_number": batch_number,
|
||||
"quantity_added": batch_quantity,
|
||||
"new_total_quantity": existing.quantity,
|
||||
"received_pack_id": resolved["pack_id"],
|
||||
"received_pack_count": resolved["pack_count"],
|
||||
"expiry_date": str(payload.expiry_date),
|
||||
"location_id": existing.location_id,
|
||||
},
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(existing)
|
||||
return serialize_batch_response(db, existing)
|
||||
|
||||
row = Batch(
|
||||
drug_variant_id=variant_id,
|
||||
|
||||
Reference in New Issue
Block a user