diff --git a/services/StockService.php b/services/StockService.php index 9d54d4b0..5c660fdf 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -249,6 +249,11 @@ class StockService extends BaseService $potentialStockEntries = $this->GetProductStockEntriesForLocation($productId, $locationId, false, $allowSubproductSubstitution); } + if ($specificStockEntryId !== 'default') + { + $potentialStockEntries = FindAllObjectsInArrayByPropertyValue($potentialStockEntries, 'stock_id', $specificStockEntryId); + } + $productStockAmount = SumArrayValue($potentialStockEntries, 'amount'); 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)'); } - if ($specificStockEntryId !== 'default') - { - $potentialStockEntries = FindAllObjectsInArrayByPropertyValue($potentialStockEntries, 'stock_id', $specificStockEntryId); - } - if ($transactionId === null) { $transactionId = uniqid();