Show to amount of "Label per unit" stock entry labels (closes #2241)

This commit is contained in:
Bernd Bestel
2023-05-22 21:23:19 +02:00
parent 55adc140b2
commit 02fe3f2119
8 changed files with 54 additions and 7 deletions

View File

@@ -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());
}
}

View File

@@ -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()

View File

@@ -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("");
}
});

View File

@@ -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("");
}
});