From 9e982979c3ccb818234b695d4d246cad5f644077 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 19 Oct 2020 20:25:42 +0200 Subject: [PATCH] Allow 4 decimals for all amount inputs (this now closes #998) --- changelog/60_UNRELEASED_2020-xx-xx.md | 1 + public/viewjs/consume.js | 16 ++++++++-------- public/viewjs/inventory.js | 8 ++++---- public/viewjs/productform.js | 4 ++-- public/viewjs/purchase.js | 10 +++++----- public/viewjs/recipeposform.js | 10 +++++----- public/viewjs/stockentryform.js | 6 +++--- public/viewjs/transfer.js | 8 ++++---- views/choreform.blade.php | 4 ++-- views/components/productamountpicker.blade.php | 4 ++-- views/components/userfieldsform.blade.php | 4 ++-- views/consume.blade.php | 4 ++-- views/inventory.blade.php | 2 +- views/productbarcodesform.blade.php | 4 ++-- views/productform.blade.php | 16 ++++++++-------- views/purchase.blade.php | 8 ++++---- views/quantityunitconversionform.blade.php | 4 ++-- views/quantityunitpluraltesting.blade.php | 4 ++-- views/shoppinglistitemform.blade.php | 4 ++-- views/stockentryform.blade.php | 4 ++-- views/stocksettings.blade.php | 4 ++-- views/transfer.blade.php | 4 ++-- 22 files changed, 67 insertions(+), 66 deletions(-) diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index 4c58496d..eba6d093 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -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) diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 69e772be..c4045316 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -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); diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index 1a851327..b2819260 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -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) diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index 73472922..0b49dfef 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -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 diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 50f75170..883a0320 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -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 diff --git a/public/viewjs/recipeposform.js b/public/viewjs/recipeposform.js index 2a2dad66..958b5b84 100644 --- a/public/viewjs/recipeposform.js +++ b/public/viewjs/recipeposform.js @@ -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"); diff --git a/public/viewjs/stockentryform.js b/public/viewjs/stockentryform.js index 732f4485..3da1e12e 100644 --- a/public/viewjs/stockentryform.js +++ b/public/viewjs/stockentryform.js @@ -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 { diff --git a/public/viewjs/transfer.js b/public/viewjs/transfer.js index f09bc165..3f90294e 100644 --- a/public/viewjs/transfer.js +++ b/public/viewjs/transfer.js @@ -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) diff --git a/views/choreform.blade.php b/views/choreform.blade.php index 3ebb9651..eed848c2 100644 --- a/views/choreform.blade.php +++ b/views/choreform.blade.php @@ -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 diff --git a/views/components/productamountpicker.blade.php b/views/components/productamountpicker.blade.php index d94cb21b..1fa50c1d 100644 --- a/views/components/productamountpicker.blade.php +++ b/views/components/productamountpicker.blade.php @@ -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', diff --git a/views/components/userfieldsform.blade.php b/views/components/userfieldsform.blade.php index f8311384..435517ed 100644 --- a/views/components/userfieldsform.blade.php +++ b/views/components/userfieldsform.blade.php @@ -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 . '"' diff --git a/views/consume.blade.php b/views/consume.blade.php index 2f40f018..fcde9ea8 100644 --- a/views/consume.blade.php +++ b/views/consume.blade.php @@ -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' => '
'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"', diff --git a/views/productbarcodesform.blade.php b/views/productbarcodesform.blade.php index 6673e958..5d4ea609 100644 --- a/views/productbarcodesform.blade.php +++ b/views/productbarcodesform.blade.php @@ -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'), diff --git a/views/productform.blade.php b/views/productform.blade.php index 623077e6..1f190b6d 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -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'), diff --git a/views/purchase.blade.php b/views/purchase.blade.php index 63c49fab..85926864 100644 --- a/views/purchase.blade.php +++ b/views/purchase.blade.php @@ -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' => '
' . $__t('Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated') . '
' @@ -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', diff --git a/views/quantityunitconversionform.blade.php b/views/quantityunitconversionform.blade.php index 432f06cc..43e82193 100644 --- a/views/quantityunitconversionform.blade.php +++ b/views/quantityunitconversionform.blade.php @@ -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' => '

'amount', 'label' => 'Amount', - 'min' => 0.01, - 'decimals' => 2, + 'min' => 0.0001, + 'decimals' => 4, 'isRequired' => false, 'value' => 1 )) diff --git a/views/shoppinglistitemform.blade.php b/views/shoppinglistitemform.blade.php index ea4cf508..16c44d24 100644 --- a/views/shoppinglistitemform.blade.php +++ b/views/shoppinglistitemform.blade.php @@ -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') )) diff --git a/views/stockentryform.blade.php b/views/stockentryform.blade.php index 2cb5af43..aa5ba706 100644 --- a/views/stockentryform.blade.php +++ b/views/stockentryform.blade.php @@ -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' => '

'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' )) diff --git a/views/transfer.blade.php b/views/transfer.blade.php index f422c9ca..22df91d7 100644 --- a/views/transfer.blade.php +++ b/views/transfer.blade.php @@ -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' => '