[FEAT/BE]Fix create avaible qty

This commit is contained in:
ragilap
2026-02-03 11:17:11 +07:00
parent d2ce0918b5
commit 82f0db107a
2 changed files with 46 additions and 14 deletions
+17 -3
View File
@@ -28,12 +28,26 @@ func MapDepletions(recordingID uint, items []validation.Depletion) []entity.Reco
return nil
}
result := make([]entity.RecordingDepletion, 0, len(items))
aggregate := make(map[uint]float64, len(items))
for _, item := range items {
if item.ProductWarehouseId == 0 || item.Qty == 0 {
continue
}
aggregate[item.ProductWarehouseId] += item.Qty
}
if len(aggregate) == 0 {
return nil
}
result := make([]entity.RecordingDepletion, 0, len(aggregate))
for warehouseID, qty := range aggregate {
if qty == 0 {
continue
}
result = append(result, entity.RecordingDepletion{
RecordingId: recordingID,
ProductWarehouseId: item.ProductWarehouseId,
Qty: item.Qty,
ProductWarehouseId: warehouseID,
Qty: qty,
})
}
return result