diff --git a/changelog/75_UNRELEASED_xxxx-xx-xx.md b/changelog/75_UNRELEASED_xxxx-xx-xx.md index 8f875380..ed5e0bcd 100644 --- a/changelog/75_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/75_UNRELEASED_xxxx-xx-xx.md @@ -14,6 +14,7 @@ - This executes the configured barcode lookup plugin with the given barcode - If the lookup was successful, the product edit page of the created product is displayed, where the product setup can be completed (if required) - After that, the transaction is continued with that product +- When using/scanning a stock entry Grocycode on the transfer page, the "Use specific stock item" dropdown (and "From location") is now also prefilled accordingly - Fixed that for the product's last price stock transactions with an empty or `0` price weren't ignored - Fixed that when copying a product, the field "Move on open" wasn't copied along diff --git a/public/viewjs/transfer.js b/public/viewjs/transfer.js index a9a15aa3..183edd83 100644 --- a/public/viewjs/transfer.js +++ b/public/viewjs/transfer.js @@ -246,6 +246,25 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) ); } + // If a stock entry Grocycode was used, prefill location_from accordingly + if ($("#product_id").data("grocycode")) + { + var gc = $("#product_id").attr("barcode").split(":"); + if (gc.length == 4) + { + Grocy.Api.Get("objects/stock?query[]=stock_id=" + gc[3], + function(stockEntries) + { + $("#location_id_from").val(stockEntries[0].location_id); + }, + function(xhr) + { + console.error(xhr); + } + ); + } + } + if (productDetails.product.enable_tare_weight_handling == 1) { $("#display_amount").attr("min", productDetails.product.tare_weight); @@ -292,8 +311,18 @@ $("#location_id_from").on('change', function(e) stockId = GetUriParam('stockId'); } + // If a stock entry Grocycode was used, preselect that one + if ($("#product_id").data("grocycode")) + { + var gc = $("#product_id").attr("barcode").split(":"); + if (gc.length == 4) + { + stockId = gc[3]; + } + } + $("#specific_stock_entry").find("option").remove().end().append(""); - if ($("#use_specific_stock_entry").is(":checked") && GetUriParam("stockId") == null) + if (!$("#use_specific_stock_entry").is(":checked") && stockId != null) { $("#use_specific_stock_entry").click(); }