Fixed total price for tare weight handling enabled products (fixes #1196)

This commit is contained in:
Bernd Bestel 2020-12-17 16:50:15 +01:00
parent bb6ef5511d
commit 9572652a8a
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 16 additions and 3 deletions

View File

@ -83,6 +83,7 @@
- Fixed that the recipes dropdown on the consume page also displayed internal recipes (thanks @kriddles) - 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 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 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 ### Shopping list improvements
- Decimal amounts are now allowed (for any product, rounded by two decimal places) - Decimal amounts are now allowed (for any product, rounded by two decimal places)

View File

@ -20,12 +20,18 @@ $('#save-purchase-button').on('click', function(e)
} }
else 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") 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; 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()) 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); 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") 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"))); $('#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")));