Allow empty QU when editing product barcodes (fixes #2526)

This commit is contained in:
Bernd Bestel 2025-01-12 14:27:19 +01:00
parent c73be7d18e
commit b6ce9eec30
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 16 additions and 1 deletions

View File

@ -17,6 +17,7 @@
- A plugin for [Open Food Facts](https://world.openfoodfacts.org/) is now included and used by default (see the `config.php` option `STOCK_BARCODE_LOOKUP_PLUGIN` and maybe change it as needed) - A plugin for [Open Food Facts](https://world.openfoodfacts.org/) is now included and used by default (see the `config.php` option `STOCK_BARCODE_LOOKUP_PLUGIN` and maybe change it as needed)
- The product name and image (and of course the barcode itself) are taken over from Open Food Facts to the product being looked up - The product name and image (and of course the barcode itself) are taken over from Open Food Facts to the product being looked up
- Optimized that when moving a product to a freezer location (so when freezing it) the due date will no longer be replaced when the product option "Default due days after freezing" is set to `0` - Optimized that when moving a product to a freezer location (so when freezing it) the due date will no longer be replaced when the product option "Default due days after freezing" is set to `0`
- Fixed that a once set quantity unit on a product barcode could not be removed on edit
### Shopping list ### Shopping list

View File

@ -8,6 +8,11 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI
if (!Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled) if (!Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled)
{ {
$("#qu_id").find("option").remove().end(); $("#qu_id").find("option").remove().end();
if (!$("#qu_id").hasAttr("required"))
{
$("#qu_id").append('<option></option>');
}
$("#qu_id").attr("data-destination-qu-name", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name); $("#qu_id").attr("data-destination-qu-name", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name);
$("#qu_id").attr("data-destination-qu-name-plural", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name_plural); $("#qu_id").attr("data-destination-qu-name-plural", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name_plural);
@ -67,6 +72,11 @@ Grocy.Components.ProductAmountPicker.AllowAnyQu = function(keepInitialQu = false
Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled = true; Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled = true;
$("#qu_id").find("option").remove().end(); $("#qu_id").find("option").remove().end();
if (!$("#qu_id").hasAttr("required"))
{
$("#qu_id").append('<option></option>');
}
Grocy.QuantityUnits.forEach(qu => Grocy.QuantityUnits.forEach(qu =>
{ {
$("#qu_id").append('<option value="' + qu.id + '" data-qu-factor="1" data-qu-name-plural="' + qu.name_plural + '">' + qu.name + '</option>'); $("#qu_id").append('<option value="' + qu.id + '" data-qu-factor="1" data-qu-name-plural="' + qu.name_plural + '">' + qu.name + '</option>');

View File

@ -92,7 +92,11 @@ if (Grocy.EditMode == "edit")
{ {
$("#display_amount").val(Grocy.EditObject.amount); $("#display_amount").val(Grocy.EditObject.amount);
$(".input-group-productamountpicker").trigger("change"); $(".input-group-productamountpicker").trigger("change");
if (Grocy.EditObject.qu_id)
{
Grocy.Components.ProductAmountPicker.SetQuantityUnit(Grocy.EditObject.qu_id); Grocy.Components.ProductAmountPicker.SetQuantityUnit(Grocy.EditObject.qu_id);
}
} }
Grocy.FrontendHelpers.ValidateForm('barcode-form'); Grocy.FrontendHelpers.ValidateForm('barcode-form');