mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Allow optional partial units of products in stock (closes #123)
This commit is contained in:
@@ -133,6 +133,19 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
$('#amount').attr('max', productDetails.stock_amount);
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
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(L('The amount cannot be lower than #1', 0.01.toLocaleString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#amount").attr("min", "1");
|
||||
$("#amount").attr("step", "1");
|
||||
$("#amount").parent().find(".invalid-feedback").text(L('The amount cannot be lower than #1', '1'));
|
||||
}
|
||||
|
||||
if ((productDetails.stock_amount || 0) === 0)
|
||||
{
|
||||
Grocy.Components.ProductPicker.SetValue('');
|
||||
|
@@ -83,6 +83,19 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
$('#new_amount').attr('not-equal', productDetails.stock_amount);
|
||||
$('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
if (productDetails.product.allow_partial_units_in_stock == 1)
|
||||
{
|
||||
$("#new_amount").attr("min", "0.01");
|
||||
$("#new_amount").attr("step", "0.01");
|
||||
$("#new_amount").parent().find(".invalid-feedback").text(L('The amount cannot be lower than #1', 0.01.toLocaleString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#new_amount").attr("min", "1");
|
||||
$("#new_amount").attr("step", "1");
|
||||
$("#new_amount").parent().find(".invalid-feedback").text(L('The amount cannot be lower than #1', '1'));
|
||||
}
|
||||
|
||||
$('#new_amount').focus();
|
||||
},
|
||||
function(xhr)
|
||||
|
@@ -9,7 +9,7 @@
|
||||
redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val());
|
||||
}
|
||||
|
||||
var jsonData = $('#product-form').serializeJSON();
|
||||
var jsonData = $('#product-form').serializeJSON({ checkboxUncheckedValue: "0" });
|
||||
Grocy.FrontendHelpers.BeginUiBusy("product-form");
|
||||
|
||||
if ($("#product-picture")[0].files.length > 0)
|
||||
|
@@ -100,6 +100,19 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
$('#price').val(productDetails.last_price);
|
||||
|
||||
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(L('The amount cannot be lower than #1', 0.01.toLocaleString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#amount").attr("min", "1");
|
||||
$("#amount").attr("step", "1");
|
||||
$("#amount").parent().find(".invalid-feedback").text(L('The amount cannot be lower than #1', '1'));
|
||||
}
|
||||
|
||||
if (productDetails.product.default_best_before_days.toString() !== '0')
|
||||
{
|
||||
if (productDetails.product.default_best_before_days == -1)
|
||||
|
@@ -52,6 +52,20 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
$("#qu_id").val(productDetails.quantity_unit_stock.id);
|
||||
}
|
||||
|
||||
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(L('The amount cannot be lower than #1', 0.01.toLocaleString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#amount").attr("min", "1");
|
||||
$("#amount").attr("step", "1");
|
||||
$("#amount").parent().find(".invalid-feedback").text(L('The amount cannot be lower than #1', '1'));
|
||||
}
|
||||
|
||||
$('#amount').focus();
|
||||
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
|
||||
},
|
||||
|
@@ -47,6 +47,20 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
function (productDetails)
|
||||
{
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
||||
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(L('The amount cannot be lower than #1', 0.01.toLocaleString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#amount").attr("min", "1");
|
||||
$("#amount").attr("step", "1");
|
||||
$("#amount").parent().find(".invalid-feedback").text(L('The amount cannot be lower than #1', '1'));
|
||||
}
|
||||
|
||||
$('#amount').focus();
|
||||
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
|
||||
},
|
||||
|
Reference in New Issue
Block a user