Use barcode amounts also for Consume/Transfer/Inventory (closes #1254)

This commit is contained in:
Bernd Bestel 2021-01-04 21:59:19 +01:00
parent d78e156609
commit 45abc99a77
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 133 additions and 14 deletions

View File

@ -8,6 +8,7 @@
- Added validation checks for most `data/config.php` settings to prevent using invalid ones (thanks @Forceu) - Added validation checks for most `data/config.php` settings to prevent using invalid ones (thanks @Forceu)
- When using reverse proxy authentication (`ReverseProxyAuthMiddleware`), _additionally_ a valid API key can now also be used for authentication (if you don't want to protect the API endpoints via your reverse proxy, however) - When using reverse proxy authentication (`ReverseProxyAuthMiddleware`), _additionally_ a valid API key can now also be used for authentication (if you don't want to protect the API endpoints via your reverse proxy, however)
- Added a new API endpoint `/system/time` to get the current server time (thanks @Forceu) - Added a new API endpoint `/system/time` to get the current server time (thanks @Forceu)
- An amount attached to a barcode is now also prefiled when scanning the product on the Consume/Transfer/Inventory page
- Fixed that some number inputs were broken when the new decimal places setting were set to `0` - Fixed that some number inputs were broken when the new decimal places setting were set to `0`
- Fixed that browser camera barcode scanning did not work on the product edit page for adding product barcodes - Fixed that browser camera barcode scanning did not work on the product edit page for adding product barcodes
- Fixed that indirect unit conversions (those between units, not product overrides) could not be used/selected - Fixed that indirect unit conversions (those between units, not product overrides) could not be used/selected

View File

@ -344,22 +344,45 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
}); });
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled)) if (document.getElementById("product_id").getAttribute("barcode") != "null")
{ {
$("#display_amount").val(1); Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"),
RefreshLocaleNumberInput(); function(barcodeResult)
$(".input-group-productamountpicker").trigger("change"); {
if (barcodeResult != null)
{
var barcode = barcodeResult[0];
Grocy.FrontendHelpers.ValidateForm("consume-form"); if (barcode != null)
if (document.getElementById("consume-form").checkValidity() === true) {
{ if (barcode.amount != null && !barcode.amount.isEmpty())
$('#save-consume-button').click(); {
} $("#display_amount").val(barcode.amount);
else $("#display_amount").select();
{ }
toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically"));
Grocy.UISound.Error(); if (barcode.qu_id != null)
} {
Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id);
}
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('consume-form');
RefreshLocaleNumberInput();
}
}
ScanModeSubmit(false);
},
function(xhr)
{
console.error(xhr);
}
);
}
else
{
ScanModeSubmit();
} }
}, },
function(xhr) function(xhr)
@ -619,3 +642,28 @@ function RefreshForm()
Grocy.FrontendHelpers.ValidateForm("consume-form"); Grocy.FrontendHelpers.ValidateForm("consume-form");
} }
function ScanModeSubmit(singleUnit = true)
{
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled))
{
if (singleUnit)
{
$("#display_amount").val(1);
}
RefreshLocaleNumberInput();
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm("consume-form");
if (document.getElementById("consume-form").checkValidity() === true)
{
$('#save-consume-button').click();
}
else
{
toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically"));
Grocy.UISound.Error();
}
}
}

View File

@ -182,6 +182,41 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
} }
if (document.getElementById("product_id").getAttribute("barcode") != "null")
{
Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"),
function(barcodeResult)
{
if (barcodeResult != null)
{
var barcode = barcodeResult[0];
if (barcode != null)
{
if (barcode.amount != null && !barcode.amount.isEmpty())
{
$("#display_amount").val(barcode.amount);
$("#display_amount").select();
}
if (barcode.qu_id != null)
{
Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id);
}
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('inventory-form');
RefreshLocaleNumberInput();
}
}
},
function(xhr)
{
console.error(xhr);
}
);
}
$('#display_amount').val(productDetails.stock_amount); $('#display_amount').val(productDetails.stock_amount);
RefreshLocaleNumberInput(); RefreshLocaleNumberInput();
$(".input-group-productamountpicker").trigger("change"); $(".input-group-productamountpicker").trigger("change");

View File

@ -192,6 +192,41 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
); );
if (document.getElementById("product_id").getAttribute("barcode") != "null")
{
Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"),
function(barcodeResult)
{
if (barcodeResult != null)
{
var barcode = barcodeResult[0];
if (barcode != null)
{
if (barcode.amount != null && !barcode.amount.isEmpty())
{
$("#display_amount").val(barcode.amount);
$("#display_amount").select();
}
if (barcode.qu_id != null)
{
Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id);
}
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('transfer-form');
RefreshLocaleNumberInput();
}
}
},
function(xhr)
{
console.error(xhr);
}
);
}
if (productDetails.product.enable_tare_weight_handling == 1) if (productDetails.product.enable_tare_weight_handling == 1)
{ {
$("#display_amount").attr("min", productDetails.product.tare_weight); $("#display_amount").attr("min", productDetails.product.tare_weight);