Prefill specific stock entry information by a scanned stock entry Grocycode on /transfer (closes #2481)

This commit is contained in:
Bernd Bestel 2024-02-24 17:48:58 +01:00
parent 88d0d32ea0
commit 6a68e410e4
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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("<option></option>");
if ($("#use_specific_stock_entry").is(":checked") && GetUriParam("stockId") == null)
if (!$("#use_specific_stock_entry").is(":checked") && stockId != null)
{
$("#use_specific_stock_entry").click();
}