diff --git a/changelog/61_UNRELEASED_xxxx-xx-xx.md b/changelog/61_UNRELEASED_xxxx-xx-xx.md index 924713bf..d6e29414 100644 --- a/changelog/61_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/61_UNRELEASED_xxxx-xx-xx.md @@ -8,6 +8,7 @@ - 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) - 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 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 diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 98e30ee4..5a3ea2f4 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -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); - RefreshLocaleNumberInput(); - $(".input-group-productamountpicker").trigger("change"); + Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"), + function(barcodeResult) + { + if (barcodeResult != null) + { + var barcode = barcodeResult[0]; - 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(); - } + 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('consume-form'); + RefreshLocaleNumberInput(); + } + } + + ScanModeSubmit(false); + }, + function(xhr) + { + console.error(xhr); + } + ); + } + else + { + ScanModeSubmit(); } }, function(xhr) @@ -619,3 +642,28 @@ function RefreshForm() 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(); + } + } +} diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index 96d9d7f1..a0b5f85a 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -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); RefreshLocaleNumberInput(); $(".input-group-productamountpicker").trigger("change"); diff --git a/public/viewjs/transfer.js b/public/viewjs/transfer.js index 5973a2ea..b679c7c6 100644 --- a/public/viewjs/transfer.js +++ b/public/viewjs/transfer.js @@ -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) { $("#display_amount").attr("min", productDetails.product.tare_weight);