From ed1607c12340ac70bc8c0682196074bee8d4680e Mon Sep 17 00:00:00 2001 From: fipwmaqzufheoxq92ebc <29818044+fipwmaqzufheoxq92ebc@users.noreply.github.com> Date: Sun, 11 Oct 2020 11:50:57 +0200 Subject: [PATCH] Fixes #1035: Check available amount after filtering by stock_entry_id --- services/StockService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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();