From 40e16db01f60b38caf512267e5eade96c4ce018a Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 11 Jul 2021 10:21:36 +0200 Subject: [PATCH] Fixed consume amount validation when consuming a parent product (fixes #1306) More a workaround for now, the max constraint is just removed when the product has child products, but the amount to be consumed is checked by StockService anyway, so should not be a problem... --- grocy.openapi.json | 4 ++++ public/viewjs/consume.js | 6 ++++++ services/StockService.php | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/grocy.openapi.json b/grocy.openapi.json index 85d60771..07e84b26 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -4480,6 +4480,10 @@ "spoil_rate_percent": { "type": "number", "format": "number" + }, + "has_childs": { + "type": "boolean", + "description": "True when the product is a parent products of others" } }, "example": { diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 082b2ed5..34ab00a1 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -127,6 +127,7 @@ }, function(xhr) { + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response); Grocy.FrontendHelpers.EndUiBusy("consume-form"); console.error(xhr); } @@ -650,6 +651,11 @@ function RefreshForm() } } + if (productDetails.has_childs) + { + $("#display_amount").removeAttr("max"); + } + Grocy.FrontendHelpers.ValidateForm("consume-form"); } diff --git a/services/StockService.php b/services/StockService.php index afbffe39..5e3a7f18 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -683,7 +683,8 @@ class StockService extends BaseService 'location' => $location, 'average_shelf_life_days' => $averageShelfLifeDays, 'spoil_rate_percent' => $spoilRate, - 'is_aggregated_amount' => $stockCurrentRow->is_aggregated_amount + 'is_aggregated_amount' => $stockCurrentRow->is_aggregated_amount, + 'has_childs' => $this->getDatabase()->products()->where('parent_product_id = :1', $product->id)->count() !== 0, ]; }