Fix consume page form validation limits for the amount input when tare weight handling is enabled (fixes #727)

This commit is contained in:
Bernd Bestel
2020-04-12 21:41:04 +02:00
parent b62d3b02e6
commit 855b24c515
2 changed files with 65 additions and 31 deletions

View File

@@ -14,6 +14,7 @@
- Fixed that best before dates were displayed on the stock overview and stock entries page even with disabled `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING` - Fixed that best before dates were displayed on the stock overview and stock entries page even with disabled `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING`
- Fixed that when editing a stock entry and setting a decimal amount, the decimal part was ignored (only possible when the product option "Allow partial units in stock" is enabled) - Fixed that when editing a stock entry and setting a decimal amount, the decimal part was ignored (only possible when the product option "Allow partial units in stock" is enabled)
- Fixed that "Default best before days" and "Default best before days after opened" on the product edit page were always shown regardless of the feature flags `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING` and `FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING` - Fixed that "Default best before days" and "Default best before days after opened" on the product edit page were always shown regardless of the feature flags `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING` and `FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING`
- Fixed that the form validation limits for the amount input and products with enabled tare weight handling were wrong
### Shopping list fixes ### Shopping list fixes
- Fixed that the "shopping list to stock workflow"-dialog was not visible in compact view - Fixed that the "shopping list to stock workflow"-dialog was not visible in compact view

View File

@@ -219,6 +219,7 @@ $("#location_id").on('change', function(e)
amount: stockEntry.amount, amount: stockEntry.amount,
text: __t("Amount: %1$s; Expires on %2$s; Bought on %3$s", stockEntry.amount, moment(stockEntry.best_before_date).format("YYYY-MM-DD"), moment(stockEntry.purchased_date).format("YYYY-MM-DD")) + "; " + openTxt text: __t("Amount: %1$s; Expires on %2$s; Bought on %3$s", stockEntry.amount, moment(stockEntry.best_before_date).format("YYYY-MM-DD"), moment(stockEntry.purchased_date).format("YYYY-MM-DD")) + "; " + openTxt
})); }));
sumValue = sumValue + parseFloat(stockEntry.amount); sumValue = sumValue + parseFloat(stockEntry.amount);
if (stockEntry.stock_id == stockId) if (stockEntry.stock_id == stockId)
@@ -227,16 +228,48 @@ $("#location_id").on('change', function(e)
} }
} }
}); });
$("#amount").attr("max", sumValue);
Grocy.Api.Get('stock/products/' + Grocy.Components.ProductPicker.GetValue(),
function(productDetails)
{
if (productDetails.product.enable_tare_weight_handling == 1)
{
$("#amount").attr("min", productDetails.product.tare_weight);
$('#amount').attr('max', sumValue + parseFloat(productDetails.product.tare_weight));
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', parseFloat(productDetails.product.tare_weight).toLocaleString(), (parseFloat(productDetails.stock_amount) + parseFloat(productDetails.product.tare_weight)).toLocaleString()));
$("#tare-weight-handling-info").removeClass("d-none");
}
else
{
$("#tare-weight-handling-info").addClass("d-none");
if (productDetails.product.allow_partial_units_in_stock == 1)
{
$("#amount").attr("min", "0.01");
$("#amount").attr("step", "0.01");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', 0.01.toLocaleString(), parseFloat(productDetails.stock_amount).toLocaleString()));
}
else
{
$("#amount").attr("min", "1");
$("#amount").attr("step", "1");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', "1", parseFloat(productDetails.stock_amount).toLocaleString()));
}
$('#amount').attr('max', sumValue);
if (sumValue == 0) if (sumValue == 0)
{ {
$("#amount").parent().find(".invalid-feedback").text(__t('There are no units available at this location')); $("#amount").parent().find(".invalid-feedback").text(__t('There are no units available at this location'));
} }
else
{
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', "1", sumValue));
} }
}, },
function (xhr)
{
console.error(xhr);
}
);
},
function(xhr) function(xhr)
{ {
console.error(xhr); console.error(xhr);