Skip to content

Commit

Permalink
#1093: Update stock quantity bug
Browse files Browse the repository at this point in the history
  • Loading branch information
s04v committed Mar 12, 2024
1 parent c8a29a9 commit 72c7882
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ public async Task UpdateStock(StockUpdateRequest stockUpdateRequest)
var product = await _productRepository.Query().FirstOrDefaultAsync(x => x.Id == stockUpdateRequest.ProductId);
var stock = await _stockRepository.Query().FirstOrDefaultAsync(x => x.ProductId == stockUpdateRequest.ProductId && x.WarehouseId == stockUpdateRequest.WarehouseId);

var adjustedQuantity = stockUpdateRequest.AdjustedQuantity;

if (adjustedQuantity < 0 && Math.Abs(adjustedQuantity) > stock.Quantity)
{
adjustedQuantity = -stock.Quantity;
}

var prevStockQuantity = product.StockQuantity;
stock.Quantity = stock.Quantity + stockUpdateRequest.AdjustedQuantity;
product.StockQuantity = product.StockQuantity + stockUpdateRequest.AdjustedQuantity;
stock.Quantity = stock.Quantity + adjustedQuantity;
product.StockQuantity = product.StockQuantity + adjustedQuantity;
var stockHistory = new StockHistory
{
ProductId = stockUpdateRequest.ProductId,
Expand Down

0 comments on commit 72c7882

Please sign in to comment.