mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
FIX[BE]Lock chickins, accumulate pending qty, use qty key
This commit is contained in:
@@ -196,6 +196,8 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) ([]enti
|
||||
}
|
||||
}
|
||||
|
||||
// CRITICAL: Validate chickins sequentially to prevent over-allocation within the same request
|
||||
// pendingQtyMap is accumulated as we validate each chickin to ensure total pending doesn't exceed available stock
|
||||
for idx, chickin := range newChikins {
|
||||
pendingQty := pendingQtyMap[chickin.ProductWarehouseId]
|
||||
desiredQty := chickinQtyMap[uint(idx)]
|
||||
@@ -210,6 +212,10 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) ([]enti
|
||||
}
|
||||
|
||||
chickinQtyMap[uint(idx)] = availableQty
|
||||
|
||||
// ACCUMULATE pending for this product warehouse so NEXT chickin in same request sees it
|
||||
// This prevents multiple chickins in same request from over-allocating the same stock
|
||||
pendingQtyMap[chickin.ProductWarehouseId] += availableQty
|
||||
}
|
||||
|
||||
approvalSvcTx := commonSvc.NewApprovalService(commonRepo.NewApprovalRepository(dbTransaction))
|
||||
|
||||
Reference in New Issue
Block a user