From 02fe3f2119fdc28a67056ff37d196e893e767252 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 22 May 2023 21:23:19 +0200 Subject: [PATCH] Show to amount of "Label per unit" stock entry labels (closes #2241) --- changelog/70_UNRELEASED_xxxx.xx.xx.md | 1 + localization/strings.pot | 5 ++++ public/js/grocy.js | 4 +-- .../viewjs/components/productamountpicker.js | 7 +++++- public/viewjs/inventory.js | 25 +++++++++++++++++-- public/viewjs/purchase.js | 13 ++++++++++ views/inventory.blade.php | 3 ++- views/purchase.blade.php | 3 ++- 8 files changed, 54 insertions(+), 7 deletions(-) diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index de386aae..120703a6 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -37,6 +37,7 @@ - When clicking a product name on the products list (master data) or on the stock journal page, the product card will now be displayed (like on the stock overview page) - When using/scanning a product barcode and the purchase or inventory page, the barcode's note will now also be prefilled (if any) - Each row on the stock journal now also has a context-/more menu for quick access to product related actions (the same as on the stock overview page) +- The amount of "Label per unit" stock entry labels (on purchase and inventory) is now displayed, to help prevent printing a lot of labels where this maybe is not intended - Fixed that hiding the "Purchased date" column (table options) on the stock entries page didn't work - Fixed that sorting by the "Value" and "Min. stock amount" columns on the stock overview page didn't work - Fixed that the consumed amount was wrong, when consuming multiple substituted subproducts at once and when multiple/different conversion factors were involved diff --git a/localization/strings.pot b/localization/strings.pot index 6fc5581c..0f4dd8af 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2421,3 +2421,8 @@ msgstr "" msgid "When displaying prices for this product, they will be related to this quantity unit" msgstr "" + +msgid "This means 1 label will be printed" +msgid_plural "This means %1$s labels will be printed" +msgstr[0] "" +msgstr[1] "" diff --git a/public/js/grocy.js b/public/js/grocy.js index 6e74c65d..97e8ac36 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -283,11 +283,11 @@ __n = function(number, singularForm, pluralForm, isQu = false) if (isQu) { - return sprintf(Grocy.TranslatorQu.n__(singularForm, pluralForm, number, number), number.toString()); + return sprintf(Grocy.TranslatorQu.n__(singularForm, pluralForm, number, number), number.toLocaleString()); } else { - return sprintf(Grocy.Translator.n__(singularForm, pluralForm, number, number), number.toString()); + return sprintf(Grocy.Translator.n__(singularForm, pluralForm, number, number), number.toLocaleString()); } } diff --git a/public/viewjs/components/productamountpicker.js b/public/viewjs/components/productamountpicker.js index b647edbf..a9a0d4d2 100644 --- a/public/viewjs/components/productamountpicker.js +++ b/public/viewjs/components/productamountpicker.js @@ -13,6 +13,11 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI conversionsForProduct.forEach(conversion => { + if (conversion.to_qu_id == destinationQuId) + { + conversion.factor = 1; + } + // Only conversions related to the destination QU are needed // + only add one conversion per to_qu_id (multiple ones can be a result of contradictory definitions = user input bullshit) if ((conversion.from_qu_id == destinationQuId || conversion.to_qu_id == destinationQuId) && !$('#qu_id option[value="' + conversion.to_qu_id + '"]').length) @@ -108,7 +113,7 @@ $(".input-group-productamountpicker").on("change", function() n = 1; } - $("#amount").val(destinationAmount.toFixed(n).replace(/0*$/g, '')); + $("#amount").val(destinationAmount.toFixed(n).replace(/0*$/g, '')).trigger("change"); }); $("#display_amount").on("keyup", function() diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index 4d76aa7a..e4054795 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -77,7 +77,7 @@ $('#save-inventory-button').on('click', function(e) ); } - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER && Number.parseFloat($("#display_amount").attr("data-estimated-booking-amount")) > 0) + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER && Number.parseFloat($("#amount").attr("data-estimated-booking-amount")) > 0) { if (Grocy.Webhooks.labelprinter !== undefined) { @@ -265,6 +265,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER) { $("#stock_label_type").val(productDetails.product.default_stock_label_type); + $("#stock_label_type").trigger("change"); } if (document.getElementById("product_id").getAttribute("barcode") != "null") @@ -440,7 +441,7 @@ $('#display_amount').on('keyup', function(e) } var estimatedBookingAmount = (newAmount - productStockAmount - containerWeight).toFixed(Grocy.UserSettings.stock_decimal_places_amounts); - $("#display_amount").attr("data-estimated-booking-amount", estimatedBookingAmount); + $("#amount").attr("data-estimated-booking-amount", estimatedBookingAmount).trigger("change"); estimatedBookingAmount = Math.abs(estimatedBookingAmount); $('#inventory-change-info').removeClass('d-none'); @@ -521,3 +522,23 @@ function UndoStockTransaction(transactionId) }; $("#display_amount").attr("min", "0"); + +$("#stock_label_type, #amount").on("change", function(e) +{ + if ($("#stock_label_type").val() == 2) + { + var estimatedBookingAmount = Number.parseFloat($("#amount").attr("data-estimated-booking-amount")); + if (estimatedBookingAmount > 0) + { + $("#stock-entry-label-info").text(__n(estimatedBookingAmount, "This means 1 label will be printed", "This means %1$s labels will be printed")); + } + else + { + $("#stock-entry-label-info").text(""); + } + } + else + { + $("#stock-entry-label-info").text(""); + } +}); diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 7a3c09c5..63123b21 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -340,6 +340,7 @@ if (Grocy.Components.ProductPicker !== undefined) if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER) { $("#stock_label_type").val(productDetails.product.default_stock_label_type); + $("#stock_label_type").trigger("change"); } $("#display_amount").focus(); @@ -719,3 +720,15 @@ function ScanModeSubmit(singleUnit = true) } } } + +$("#stock_label_type, #amount").on("change", function(e) +{ + if ($("#stock_label_type").val() == 2) + { + $("#stock-entry-label-info").text(__n(Number.parseFloat($("#amount").val()), "This means 1 label will be printed", "This means %1$s labels will be printed")); + } + else + { + $("#stock-entry-label-info").text(""); + } +}); diff --git a/views/inventory.blade.php b/views/inventory.blade.php index ea5a3505..c72fddaa 100644 --- a/views/inventory.blade.php +++ b/views/inventory.blade.php @@ -123,7 +123,8 @@ -
{{ $__t('A quantity unit is required') }}
+
@endif diff --git a/views/purchase.blade.php b/views/purchase.blade.php index 181b748a..43f70abc 100644 --- a/views/purchase.blade.php +++ b/views/purchase.blade.php @@ -158,7 +158,8 @@ -
{{ $__t('A quantity unit is required') }}
+
@endif