From f4874ed8d09c53f087df85881f6ae99121751f8b Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 17 Apr 2023 19:54:24 +0200 Subject: [PATCH] Prefill barcode note on /purchase and /inventory (closes #2193) --- changelog/70_UNRELEASED_xxxx.xx.xx.md | 1 + public/viewjs/inventory.js | 13 +++++++++---- public/viewjs/purchase.js | 13 +++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index ce3c0cde..75f96e75 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -32,6 +32,7 @@ - Changed that for the product's average and last price (and for the price history chart) stock transactions with an empty or `0` price are ignored - Added a filter option to only show currently out-of-stock products on the products list (master data) page - When clicking the product name on the products list (master data) 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) - 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/public/viewjs/inventory.js b/public/viewjs/inventory.js index b8197ed6..d5a7bb9f 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -272,23 +272,28 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"), function(barcodeResult) { - if (barcodeResult != null) + if (barcodeResult) { var barcode = barcodeResult[0]; - if (barcode != null) + if (barcode) { - if (barcode.amount != null) + if (barcode.amount) { $("#display_amount").val(barcode.amount); $("#display_amount").select(); } - if (barcode.qu_id != null) + if (barcode.qu_id) { Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id); } + if (barcode.note) + { + $("#note").val(barcode.note); + } + $(".input-group-productamountpicker").trigger("change"); Grocy.FrontendHelpers.ValidateForm('inventory-form'); RefreshLocaleNumberInput(); diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 71254ee1..4274a245 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -357,20 +357,20 @@ if (Grocy.Components.ProductPicker !== undefined) Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"), function(barcodeResult) { - if (barcodeResult != null) + if (barcodeResult) { var barcode = barcodeResult[0]; $("#purchase-form").attr("data-used-barcode", barcode.id); - if (barcode != null) + if (barcode) { - if (barcode.amount != null) + if (barcode.amount) { $("#display_amount").val(barcode.amount); $("#display_amount").select(); } - if (barcode.qu_id != null) + if (barcode.qu_id) { Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id); } @@ -386,6 +386,11 @@ if (Grocy.Components.ProductPicker !== undefined) $("#price-type-total-price").click(); } + if (barcode.note) + { + $("#note").val(barcode.note); + } + $(".input-group-productamountpicker").trigger("change"); Grocy.FrontendHelpers.ValidateForm('purchase-form'); RefreshLocaleNumberInput();