Allow 4 decimals for all amount inputs (this now closes #998)

This commit is contained in:
Bernd Bestel 2020-10-19 20:25:42 +02:00
parent 80beff2cae
commit 9e982979c3
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
22 changed files with 67 additions and 66 deletions

View File

@ -33,6 +33,7 @@
- For products with tare weight handling enabled, it's now optionally possible to consume a fixed/exact amount (just like for "normal" products) in case you don't want to weigh the whole container this time (new checkbox on the consume page) (thanks @fipwmaqzufheoxq92ebc)
- The stock overview page now also shows the value - new column and also the total value in the header (thanks @kriddles)
- It's now possible to set a custom purchased date on purchase (new field on the purchase page, hidden by default - enable it by a new stock setting (top right corner settings menu)) (thanks @kriddles)
- Improved that all amount inputs now allow 4 decimals (when the product option "Allow partial units in stock" is enabled)
- Fixed that it was not possible to leave the "Barcode(s)" on the product edit page by `TAB`
- Fixed that when adding products through a product picker workflow and when the created products contains special characters, the product was not preselected on the previous page (thanks @Forceu)
- Fixed that when editing a product the default store was not visible / always empty regardless if the product had one set (thanks @kriddles)

View File

@ -326,15 +326,15 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
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()));
$("#amount").attr("min", "0.0001");
$("#amount").attr("step", ".0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', 0.0001.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 }), parseFloat(productDetails.stock_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
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").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', "1", parseFloat(productDetails.stock_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
if (productDetails.product.enable_tare_weight_handling == 1)
@ -571,15 +571,15 @@ function RefreshForm()
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()));
$("#amount").attr("min", "0.0001");
$("#amount").attr("step", ".0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', 0.0001.toLocaleString(), parseFloat(productDetails.stock_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
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").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', "1", parseFloat(productDetails.stock_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
$('#amount').attr('max', sumValue);

View File

@ -132,15 +132,15 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
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 %1$s or equal %2$s', 0.01.toLocaleString(), productDetails.stock_amount.toLocaleString()));
$("#new_amount").attr("min", "0.0001");
$("#new_amount").attr("step", ".0001");
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %1$s or equal %2$s', 0.0001.toLocaleString(), productDetails.stock_amount.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
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 %1$s or equal %2$s', '0', productDetails.stock_amount.toLocaleString()));
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %1$s or equal %2$s', '0', productDetails.stock_amount.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
if (productDetails.product.enable_tare_weight_handling == 1)

View File

@ -325,9 +325,9 @@ $("#allow_partial_units_in_stock").on("click", function()
if (this.checked)
{
$("#min_stock_amount").attr("min", "0.0000");
$("#min_stock_amount").attr("step", "0.0001");
$("#min_stock_amount").attr("step", ".0001");
$("#qu_factor_purchase_to_stock").attr("min", "0.0001");
$("#qu_factor_purchase_to_stock").attr("step", "0.0001");
$("#qu_factor_purchase_to_stock").attr("step", ".0001");
$("#qu_factor_purchase_to_stock").parent().find(".invalid-feedback").text(__t('This cannot be lower than %1$s and must be a valid number with max. %2$s decimal places', 0.0001.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 4 }), '4'));
}
else

View File

@ -259,9 +259,9 @@ if (Grocy.Components.ProductPicker !== undefined)
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 cannot be lower than %s', 0.01.toLocaleString()));
$("#amount").attr("min", "0.0001");
$("#amount").attr("step", ".0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', 0.0001.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
else
{
@ -274,8 +274,8 @@ if (Grocy.Components.ProductPicker !== undefined)
{
var minAmount = parseFloat(productDetails.product.tare_weight) / qu_factor_purchase_to_stock + parseFloat(productDetails.stock_amount);
$("#amount").attr("min", minAmount);
$("#amount").attr("step", "0.0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', minAmount.toLocaleString()));
$("#amount").attr("step", ".0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', minAmount.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
$("#tare-weight-handling-info").removeClass("d-none");
}
else

View File

@ -64,9 +64,9 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
if (productDetails.product.allow_partial_units_in_stock == 1)
{
$("#display_amount").attr("min", "0.01");
$("#display_amount").attr("step", "0.01");
$("#display_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', 0.01.toLocaleString()));
$("#display_amount").attr("min", "0.0001");
$("#display_amount").attr("step", ".0001");
$("#display_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', 0.0001.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
else
{
@ -153,8 +153,8 @@ $("#only_check_single_unit_in_stock").on("click", function()
{
if (this.checked)
{
$("#display_amount").attr("min", "0.01");
$("#display_amount").attr("step", "0.01");
$("#display_amount").attr("min", "0.0001");
$("#display_amount").attr("step", ".0001");
$("#display_amount").parent().find(".invalid-feedback").text(__t("This cannot be negative"));
Grocy.Components.ProductAmountPicker.AllowAnyQu(true);
Grocy.FrontendHelpers.ValidateForm("recipe-pos-form");

View File

@ -102,9 +102,9 @@ Grocy.Api.Get('stock/products/' + Grocy.EditObjectProductId,
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 cannot be lower than %1$s', 0.01.toLocaleString()));
$("#amount").attr("min", "0.0001");
$("#amount").attr("step", ".0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %1$s', 0.0001.toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
else
{

View File

@ -187,15 +187,15 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
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()));
$("#amount").attr("min", "0.0001");
$("#amount").attr("step", ".0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', 0.0001.toLocaleString(), parseFloat(productDetails.stock_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
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").parent().find(".invalid-feedback").text(__t('The amount must be between %1$s and %2$s', "1", parseFloat(productDetails.stock_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 })));
}
if (productDetails.product.enable_tare_weight_handling == 1)

View File

@ -255,8 +255,8 @@
'id' => 'product_amount',
'label' => 'Amount',
'hintId' => 'amount_qu_unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'isRequired' => false,
'value' => $value

View File

@ -11,8 +11,8 @@
@include('components.numberpicker', array(
'id' => 'display_amount',
'label' => 'Amount',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('This cannot be negative and must be an integral number'),
'additionalGroupCssClasses' => 'col-4 mb-1',

View File

@ -41,8 +41,8 @@
'id' => '',
'label' => $userfield->caption,
'noNameAttribute' => true,
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'isRequired' => false,
'additionalCssClasses' => 'userfield-input',
'additionalAttributes' => 'data-userfield-name="' . $userfield->name . '"'

View File

@ -54,8 +54,8 @@
'id' => 'amount',
'label' => 'Amount',
'hintId' => 'amount_qu_unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => 0,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalHtmlContextHelp' => '<div id="tare-weight-handling-info"

View File

@ -23,7 +23,7 @@
'label' => 'New amount',
'hintId' => 'new_amount_qu_unit',
'min' => 0,
'decimals' => 2,
'decimals' => 4,
'value' => 1,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '0'),
'additionalAttributes' => 'data-not-equal="-1"',

View File

@ -55,8 +55,8 @@
@include('components.numberpicker', array(
'id' => 'qu_factor_purchase_to_stock',
'label' => 'Factor purchase to stock quantity unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'isRequired' => true,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),

View File

@ -142,8 +142,8 @@
@include('components.numberpicker', array(
'id' => 'min_stock_amount',
'label' => 'Minimum stock amount',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '0'),
'additionalGroupCssClasses' => 'mb-1'
@ -245,8 +245,8 @@
@include('components.numberpicker', array(
'id' => 'qu_factor_purchase_to_stock',
'label' => 'Factor purchase to stock quantity unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalCssClasses' => 'input-group-qu',
@ -287,8 +287,8 @@
@include('components.numberpicker', array(
'id' => 'tare_weight',
'label' => 'Tare weight',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('This cannot be lower than %s', '0'),
'additionalAttributes' => $additionalAttributes,
@ -316,8 +316,8 @@
@include('components.numberpicker', array(
'id' => 'calories',
'label' => 'Energy (kcal)',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '0'),
'hint' => $__t('Per stock quantity unit'),

View File

@ -47,8 +47,8 @@
'id' => 'amount',
'label' => 'Amount',
'hintId' => 'amount_qu_unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalHtmlContextHelp' => '<div id="tare-weight-handling-info"
class="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>'
@ -135,8 +135,8 @@
@include('components.numberpicker', array(
'id' => 'qu_factor_purchase_to_stock',
'label' => 'Factor purchase to stock quantity unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'additionalGroupCssClasses' => 'd-none',
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalCssClasses' => 'input-group-qu',

View File

@ -81,8 +81,8 @@
@include('components.numberpicker', array(
'id' => 'factor',
'label' => 'Factor',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('This cannot be lower than %1$s and must be a valid number with max. %2$s decimal places', '0', '3'),
'additionalHtmlElements' => '<p id="qu-conversion-info"

View File

@ -38,8 +38,8 @@
@include('components.numberpicker', array(
'id' => 'amount',
'label' => 'Amount',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'isRequired' => false,
'value' => 1
))

View File

@ -64,8 +64,8 @@
'id' => 'amount',
'label' => 'Amount',
'hintId' => 'amount_qu_unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => $value,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '0.01')
))

View File

@ -66,8 +66,8 @@
'id' => 'qu_factor_purchase_to_stock',
'label' => 'Factor purchase to stock quantity unit',
'value' => $stockEntry->qu_factor_purchase_to_stock,
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalCssClasses' => 'input-group-qu',
'additionalHtmlElements' => '<p id="qu-conversion-info"

View File

@ -71,7 +71,7 @@
'additionalAttributes' => 'data-setting-key="stock_default_purchase_amount"',
'label' => 'Default amount for purchase',
'min' => 0,
'decimals' => 2,
'decimals' => 4,
'invalidFeedback' => $__t('This cannot be lower than %s', '1'),
'additionalCssClasses' => 'user-setting-control'
))
@ -82,7 +82,7 @@
'additionalAttributes' => 'data-setting-key="stock_default_consume_amount"',
'label' => 'Default amount for consume',
'min' => 0,
'decimals' => 2,
'decimals' => 4,
'invalidFeedback' => $__t('This cannot be lower than %s', '1'),
'additionalCssClasses' => 'user-setting-control'
))

View File

@ -46,8 +46,8 @@
'id' => 'amount',
'label' => 'Amount',
'hintId' => 'amount_qu_unit',
'min' => 0.01,
'decimals' => 2,
'min' => 0.0001,
'decimals' => 4,
'value' => 1,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalHtmlContextHelp' => '<div id="tare-weight-handling-info"