From 28276191cc0e521a5028e9ffc9125a348bb23307 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 14 Nov 2020 22:51:06 +0100 Subject: [PATCH] Don't allow tare weight handling enabled products to be opened (closes #770) --- changelog/60_UNRELEASED_2020-xx-xx.md | 1 + public/viewjs/consume.js | 2 +- services/StockService.php | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index 3537de7e..96dcbf25 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -60,6 +60,7 @@ _- (Because the stock quantity unit is now the base for everything, it cannot be - Fixed that `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING` is set to `false`, the purchase page validation failed (thanks @fipwmaqzufheoxq92ebc) - Fixed that consuming products with enabled tare weight handling did not work on the stock entries page (also fixed that opening those products is not possible there) - Fixed that the recipes dropdown on the consume page also displayed internal recipes (thanks @kriddles) +- Fixed that opening tare weight handling enabled products is not possible via the UI and the API (as this makes no sense) ### Shopping list improvements - Decimal amounts are now allowed (for any product, rounded by two decimal places) diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index f4020faf..07b04842 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -372,7 +372,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) $('#display_amount').focus(); } - if (productDetails.stock_amount == productDetails.stock_amount_opened) + if (productDetails.stock_amount == productDetails.stock_amount_opened || productDetails.product.enable_tare_weight_handling == 1) { $("#save-mark-as-open-button").addClass("disabled"); } diff --git a/services/StockService.php b/services/StockService.php index df045332..da7ee563 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -740,6 +740,11 @@ class StockService extends BaseService $potentialStockEntries = $this->GetProductStockEntries($productId, true); $product = $this->getDatabase()->products($productId); + if ($product->enable_tare_weight_handling == 1) + { + throw new \Exception('Opening tare weight handling enabled products is not supported'); + } + if ($amount > $productStockAmountUnopened) { throw new \Exception('Amount to be opened cannot be > current unopened stock amount');