From af1f2aef961179f7f8d9f6d072727d3d057da239 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Fri, 5 Apr 2024 20:12:11 +0200 Subject: [PATCH] Don't allow amounts <= 0 on purchase/consume References https://github.com/grocy/grocy/issues/2156#issuecomment-2040336492 --- services/StockService.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/StockService.php b/services/StockService.php index 86c0b4f5..56b42b49 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -113,6 +113,12 @@ class StockService extends BaseService throw new \Exception('Product does not exist or is inactive'); } + + if ($amount <= 0) + { + throw new \Exception('Amount can\'t be <= 0'); + } + $productDetails = (object)$this->GetProductDetails($productId); // Tare weight handling @@ -356,6 +362,11 @@ class StockService extends BaseService throw new \Exception('Product does not exist or is inactive'); } + if ($amount <= 0) + { + throw new \Exception('Amount can\'t be <= 0'); + } + if ($locationId !== null && !$this->LocationExists($locationId)) { throw new \Exception('Location does not exist');