Properly show and handle that the new amount during inventory cannot equal the current stock amount (this now closes #224)

This commit is contained in:
Bernd Bestel 2019-05-03 19:08:54 +02:00
parent 7fc4992b3a
commit 595171afa5
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 20 additions and 5 deletions

View File

@ -1203,3 +1203,6 @@ msgstr[1] ""
msgid "Consume %s of %s"
msgstr ""
msgid "The amount cannot be lower than %s or equal %s"
msgstr ""

View File

@ -13,3 +13,15 @@ $(".numberpicker-up-button").unbind('click').on("click", function()
$(inputElement).trigger('keyup');
$(inputElement).trigger('change');
});
$(".numberpicker").on("keyup", function()
{
if ($(this).data("not-equal") && !$(this).data("not-equal").toString().isEmpty() && $(this).data("not-equal") == $(this).val())
{
$(this)[0].setCustomValidity("error");
}
else
{
$(this)[0].setCustomValidity("");
}
});

View File

@ -84,26 +84,26 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
$('#new_amount').attr('not-equal', productDetails.stock_amount);
$('#new_amount').attr('data-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(__t('The amount cannot be lower than %s', 0.01.toLocaleString()));
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s or equal %s', 0.01.toLocaleString(), productDetails.stock_amount.toLocaleString()));
}
else
{
$("#new_amount").attr("min", "0");
$("#new_amount").attr("step", "1");
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '0'));
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s or equal %s', '0', productDetails.stock_amount.toLocaleString()));
}
if (productDetails.product.enable_tare_weight_handling == 1)
{
$("#new_amount").attr("min", productDetails.product.tare_weight);
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', parseFloat(productDetails.product.tare_weight).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 })));
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s or equal %s', parseFloat(productDetails.product.tare_weight).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), productDetails.stock_amount.toLocaleString()));
$("#tare-weight-handling-info").removeClass("d-none");
}
else

View File

@ -23,7 +23,7 @@
'min' => 0,
'value' => 1,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '0'),
'additionalAttributes' => 'data-notequal="notequal" not-equal="-1"',
'additionalAttributes' => 'data-not-equal="-1"',
'additionalHtmlElements' => '<div id="inventory-change-info" class="form-text text-muted small d-none"></div>',
'additionalHtmlContextHelp' => '<div id="tare-weight-handling-info" class="text-small text-info font-italic d-none">' . $__t('Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated') . '</div>'
))