Fixes #1035: Check available amount after filtering by stock_entry_id

This commit is contained in:
fipwmaqzufheoxq92ebc 2020-10-11 11:50:57 +02:00
parent 9c92ec4748
commit ed1607c123
No known key found for this signature in database
GPG Key ID: F4DF989490C2ADB7

View File

@ -249,6 +249,11 @@ class StockService extends BaseService
$potentialStockEntries = $this->GetProductStockEntriesForLocation($productId, $locationId, false, $allowSubproductSubstitution); $potentialStockEntries = $this->GetProductStockEntriesForLocation($productId, $locationId, false, $allowSubproductSubstitution);
} }
if ($specificStockEntryId !== 'default')
{
$potentialStockEntries = FindAllObjectsInArrayByPropertyValue($potentialStockEntries, 'stock_id', $specificStockEntryId);
}
$productStockAmount = SumArrayValue($potentialStockEntries, 'amount'); $productStockAmount = SumArrayValue($potentialStockEntries, 'amount');
if ($amount > $productStockAmount) if ($amount > $productStockAmount)
@ -256,11 +261,6 @@ class StockService extends BaseService
throw new \Exception('Amount to be consumed cannot be > current stock amount (if supplied, at the desired location)'); throw new \Exception('Amount to be consumed cannot be > current stock amount (if supplied, at the desired location)');
} }
if ($specificStockEntryId !== 'default')
{
$potentialStockEntries = FindAllObjectsInArrayByPropertyValue($potentialStockEntries, 'stock_id', $specificStockEntryId);
}
if ($transactionId === null) if ($transactionId === null)
{ {
$transactionId = uniqid(); $transactionId = uniqid();