mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FEAT/BE]Fix create avaible qty
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user