From 886721e9726a14bd6d229687df23b18318b0011a Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 13 Apr 2020 17:29:00 +0200 Subject: [PATCH] Fixed consuming tare weight handling enabled products from the stock overview page (fixes #731) --- changelog/58_UNRELEASED_2020-xx-xx.md | 1 + public/viewjs/stockoverview.js | 11 ++++++++++- views/stockoverview.blade.php | 7 ++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/changelog/58_UNRELEASED_2020-xx-xx.md b/changelog/58_UNRELEASED_2020-xx-xx.md index ae4b3779..133fddea 100644 --- a/changelog/58_UNRELEASED_2020-xx-xx.md +++ b/changelog/58_UNRELEASED_2020-xx-xx.md @@ -18,6 +18,7 @@ - Fixed that the form validation limits for the amount input and products with enabled tare weight handling were wrong - Fixed that the price was saved wrong for products with a different purchase/stock quantity unit when using "Total price" on purchase (resulted for example in wrong recipe costs) - Fixed that undoing "product-opened"-actions was not possible +- Fixed/improved consuming from the stock overview page for products with enabled tare weight handling ("consume 1" button is now disabled for such products, "consume all" works again) ### Shopping list fixes - Fixed that the "shopping list to stock workflow"-dialog was not visible in compact view diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index 1735e3f8..8d90abf1 100644 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -77,6 +77,7 @@ $(document).on('click', '.product-consume-button', function(e) var productId = $(e.currentTarget).attr('data-product-id'); var consumeAmount = $(e.currentTarget).attr('data-consume-amount'); + var originalTotalStockAmount = $(e.currentTarget).attr('data-original-total-stock-amount'); var wasSpoiled = $(e.currentTarget).hasClass("product-consume-button-spoiled"); Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount, 'spoiled': wasSpoiled }, @@ -85,7 +86,15 @@ $(document).on('click', '.product-consume-button', function(e) Grocy.Api.Get('stock/products/' + productId, function(result) { - var toastMessage = __t('Removed %1$s of %2$s from stock', consumeAmount.toString() + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; + if (result.product.enable_tare_weight_handling == 1) + { + var toastMessage = __t('Removed %1$s of %2$s from stock', parseFloat(originalTotalStockAmount).toString() + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; + } + else + { + var toastMessage = __t('Removed %1$s of %2$s from stock', consumeAmount.toString() + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; + } + if (wasSpoiled) { toastMessage += " (" + __t("Spoiled") + ")"; diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index cbe628ce..98fe643c 100644 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -100,7 +100,7 @@ @foreach($currentStock as $currentStockEntry) amount > 0) table-warning @elseif (FindObjectInArrayByPropertyValue($missingProducts, 'id', $currentStockEntry->product_id) !== null) table-info @endif"> - + data-consume-amount="@if(FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->enable_tare_weight_handling == 1){{FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->tare_weight}}@else{{$currentStockEntry->amount}}@endif" + data-original-total-stock-amount="{{$currentStockEntry->amount}}"> {{ $__t('All') }} @if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING) -