Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1093: Update stock quantity bug #1094

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
hishamco marked this conversation as resolved.
Show resolved Hide resolved
{
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