From 9572652a8afab7af9f276beb6aa65af1738a5e5c Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 17 Dec 2020 16:50:15 +0100 Subject: [PATCH] Fixed total price for tare weight handling enabled products (fixes #1196) --- changelog/60_UNRELEASED_2020-xx-xx.md | 1 + public/viewjs/purchase.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index 69ec86b4..74ea7cfc 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -83,6 +83,7 @@ - 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) - Fixed that undoing a consume transaction of an opened item added it back to stock unopened +- Fixed that a "Total price" on purchase was not handled correctly for tare weight handling enabled products (the total price was related to the amount including the tare weight) ### Shopping list improvements - Decimal amounts are now allowed (for any product, rounded by two decimal places) diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 29a28c0c..e206018a 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -20,12 +20,18 @@ $('#save-purchase-button').on('click', function(e) } else { - var price = parseFloat(jsonForm.price * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices); + var amount = jsonForm.display_amount; + if (BoolVal(productDetails.product.enable_tare_weight_handling)) + { + amount -= parseFloat(productDetails.product.tare_weight); + } + var price = parseFloat(jsonForm.price * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices); if ($("input[name='price-type']:checked").val() == "total-price") { - price = parseFloat(price / jsonForm.display_amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices); + price = parseFloat(price / amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices); } + jsonData.price = price; } @@ -467,10 +473,16 @@ function refreshPriceHint() if ($("input[name='price-type']:checked").val() == "total-price" || $("#qu_id").attr("data-destination-qu-name") != $("#qu_id option:selected").text()) { + var amount = $('#display_amount').val(); + if (BoolVal(CurrentProductDetails.product.enable_tare_weight_handling)) + { + amount -= parseFloat(CurrentProductDetails.product.tare_weight); + } + var price = parseFloat($('#price').val() * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices); if ($("input[name='price-type']:checked").val() == "total-price") { - price = parseFloat(price / $('#display_amount').val()).toFixed(Grocy.UserSettings.stock_decimal_places_prices); + price = parseFloat(price / amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices); } $('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name")));