mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Fix consume page form validation limits for the amount input when tare weight handling is enabled (fixes #727)
This commit is contained in:
parent
b62d3b02e6
commit
855b24c515
@ -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 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 the form validation limits for the amount input and products with enabled tare weight handling were wrong
|
||||
|
||||
### Shopping list fixes
|
||||
- Fixed that the "shopping list to stock workflow"-dialog was not visible in compact view
|
||||
|
@ -200,49 +200,82 @@ $("#location_id").on('change', function(e)
|
||||
}
|
||||
|
||||
if (locationId)
|
||||
{
|
||||
Grocy.Api.Get("stock/products/" + Grocy.Components.ProductPicker.GetValue() + '/entries',
|
||||
function(stockEntries)
|
||||
{
|
||||
Grocy.Api.Get("stock/products/" + Grocy.Components.ProductPicker.GetValue() + '/entries',
|
||||
function(stockEntries)
|
||||
{
|
||||
stockEntries.forEach(stockEntry =>
|
||||
{
|
||||
stockEntries.forEach(stockEntry =>
|
||||
var openTxt = __t("Not opened");
|
||||
if (stockEntry.open == 1)
|
||||
{
|
||||
var openTxt = __t("Not opened");
|
||||
if (stockEntry.open == 1)
|
||||
openTxt = __t("Opened");
|
||||
}
|
||||
|
||||
if (stockEntry.location_id == locationId)
|
||||
{
|
||||
$("#specific_stock_entry").append($("<option>", {
|
||||
value: stockEntry.stock_id,
|
||||
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
|
||||
}));
|
||||
|
||||
sumValue = sumValue + parseFloat(stockEntry.amount);
|
||||
|
||||
if (stockEntry.stock_id == stockId)
|
||||
{
|
||||
openTxt = __t("Opened");
|
||||
$("#specific_stock_entry").val(stockId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (stockEntry.location_id == locationId)
|
||||
Grocy.Api.Get('stock/products/' + Grocy.Components.ProductPicker.GetValue(),
|
||||
function(productDetails)
|
||||
{
|
||||
if (productDetails.product.enable_tare_weight_handling == 1)
|
||||
{
|
||||
$("#specific_stock_entry").append($("<option>", {
|
||||
value: stockEntry.stock_id,
|
||||
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
|
||||
}));
|
||||
sumValue = sumValue + parseFloat(stockEntry.amount);
|
||||
$("#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 (stockEntry.stock_id == stockId)
|
||||
if (productDetails.product.allow_partial_units_in_stock == 1)
|
||||
{
|
||||
$("#specific_stock_entry").val(stockId);
|
||||
$("#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)
|
||||
{
|
||||
$("#amount").parent().find(".invalid-feedback").text(__t('There are no units available at this location'));
|
||||
}
|
||||
}
|
||||
});
|
||||
$("#amount").attr("max", sumValue);
|
||||
if (sumValue == 0)
|
||||
},
|
||||
function (xhr)
|
||||
{
|
||||
$("#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)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
|
Loading…
x
Reference in New Issue
Block a user