Grocycode, label printing (#1500)

* Grocycode: Productpicker, StockService

* Grocycode: Datamatrix generation

* Grocycode: Display in UI, make Images downloadable

* Grocycode: Do not show on product card

* Grocycode: Stockentry Label view

* Grocycode: Webhooks & Labelprinter Feature

* Grocycode: Manual Label printing

* Grocycode: Print Label from product form

* Quagga2: use zxing for DataMatrix recognition

* Grocycode: Default settings for label printing

* Prepare merge of master

* Grocycode: docs

* Docs: label printing webhook

* Review

- "grocy" is currently written lower-case everywhere, so let's do this also for "grocycode"
- Unified phrases / capitalization
- Minor UI adjustments (mainly context menu item ordering / ordering/spacing on product edit page)
- Documented API changes for Swagger UI (grocy.openapi.json)
- Reverted German localizations (those are managed via Transifex; would cause conflicts when manually edited - will import them later there)
- Reverted a somehow messed up localization string (productform/help text for `cumulate_min_stock_amount_of_sub_products`)
- Suppress deprecation warnings when generating Datamatrix PNG (otherwise the PNG is invalid, https://github.com/jucksearm/php-barcode/issues/3)
- Default `FEATURE_FLAG_LABELPRINTER` to disabled

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
Katharina Bogad
2021-06-12 17:21:12 +02:00
committed by GitHub
parent d23fda245e
commit 2471e78188
32 changed files with 27100 additions and 25 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -476,6 +476,24 @@ Grocy.FrontendHelpers.DeleteUserSetting = function(settingsKey, reloadPageOnSucc
);
}
Grocy.FrontendHelpers.RunWebhook = function(webhook, data, repetitions = 1)
{
Object.assign(data, webhook.extra_data);
var hasAlreadyFailed = false;
for (i = 0; i < repetitions; i++)
{
$.post(webhook.hook, data).fail(function(req, status, errorThrown)
{
if (!hasAlreadyFailed)
{
hasAlreadyFailed = true;
Grocy.FrontendHelpers.ShowGenericError(__t("Error while executing WebHook", { "status": status, "errorThrown": errorThrown }));
}
});
}
}
$(document).on("keyup paste change", "input, textarea", function()
{
$(this).closest("form").addClass("is-dirty");

View File

@@ -1,5 +1,9 @@
Grocy.Components.BarcodeScanner = {};
//import Quagga2DatamatrixReader from '../../components_unmanaged/quagga2-reader-datamatrix/index.js'
Quagga.registerReader("datamatrix", Quagga2DatamatrixReader);
Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = false;
Grocy.Components.BarcodeScanner.CheckCapabilities = async function()
{
@@ -96,7 +100,8 @@ Grocy.Components.BarcodeScanner.StartScanning = function()
readers: [
"ean_reader",
"ean_8_reader",
"code_128_reader"
"code_128_reader",
"datamatrix"
],
debug: {
showCanvas: Grocy.UserSettings.quagga2_debug,

View File

@@ -147,7 +147,23 @@ $('#product_id_text_input').on('blur', function(e)
$('#product_id').attr("barcode", "null");
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*=\"" + input + ",\"]").first();
var possibleOptionElement = [];
// did we enter a grocycode?
if (input.startsWith("grcy"))
{
var gc = input.split(":");
if (gc[1] == "p")
{
// find product id
possibleOptionElement = $("#product_id option[value=\"" + gc[2] + "\"]").first();
$("#product_id").data("grocycode", true);
}
}
else // process barcode as usual
{
possibleOptionElement = $("#product_id option[data-additional-searchdata*=\"" + input + ",\"]").first();
}
if (GetUriParam('flow') === undefined && input.length > 0 && possibleOptionElement.length > 0)
{

View File

@@ -223,6 +223,18 @@ $("#location_id").on('change', function(e)
{
stockId = GetUriParam('stockId');
}
else
{
// try to get stock id from grocycode
if ($("#product_id").data("grocycode"))
{
var gc = $("#product_id").attr("barcode").split(":");
if (gc.length == 4)
{
stockId = gc[3];
}
}
}
if (locationId)
{
@@ -249,6 +261,7 @@ $("#location_id").on('change', function(e)
if (stockEntry.stock_id == stockId)
{
$("#use_specific_stock_entry").click();
$("#specific_stock_entry").val(stockId);
}
}

View File

@@ -301,6 +301,21 @@ $('#name').focus();
$('.input-group-qu').trigger('change');
Grocy.FrontendHelpers.ValidateForm('product-form');
$(document).on('click', '.stockentry-grocycode-product-label-print', function(e)
{
e.preventDefault();
document.activeElement.blur();
var productId = $(e.currentTarget).attr('data-product-id');
Grocy.Api.Get('stock/products/' + productId + '/printlabel', function(labelData)
{
if (Grocy.Webhooks.labelprinter !== undefined)
{
Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, labelData);
}
});
});
$(document).on('click', '.qu-conversion-delete-button', function(e)
{
var objectId = $(e.currentTarget).attr('data-qu-conversion-id');
@@ -388,6 +403,22 @@ $('#qu_id_stock').change(function(e)
}
});
$('#allow_label_per_unit').on('change', function()
{
if (this.checked)
{
$('#label-option-per-unit').prop("disabled", false);
}
else
{
if ($('#default_print_stock_label').val() == "2")
{
$("#default_print_stock_label").val("0");
}
$('#label-option-per-unit').prop("disabled", true);
}
});
$(window).on("message", function(e)
{
var data = e.originalEvent.data;

View File

@@ -23,6 +23,7 @@ $('#save-purchase-button').on('click', function(e)
{
var jsonData = {};
jsonData.amount = jsonForm.amount;
jsonData.print_stock_label = jsonForm.print_stock_label
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
@@ -116,6 +117,30 @@ $('#save-purchase-button').on('click', function(e)
}
var successMessage = __t('Added %1$s of %2$s to stock', amountMessage + " " + __n(amountMessage, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockTransaction(\'' + result[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER)
{
if (Grocy.Webhooks.labelprinter !== undefined)
{
var post_data = {};
post_data.product = productDetails.product.name;
post_data.grocycode = 'grcy:p:' + jsonForm.product_id + ":" + result[0].stock_id
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
{
post_data.duedate = __t('DD') + ': ' + result[0].best_before_date
}
if (jsonForm.print_stock_label > 0)
{
var reps = 1;
if (jsonForm.print_stock_label == 2)
{
reps = Math.floor(jsonData.amount);
}
Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, post_data, reps);
}
}
}
if (GetUriParam("embedded") !== undefined)
{
window.parent.postMessage(WindowMessageBag("ProductChanged", jsonForm.product_id), Grocy.BaseUrl);
@@ -279,6 +304,23 @@ if (Grocy.Components.ProductPicker !== undefined)
}
}
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER)
{
$("#print_stock_label").val(productDetails.product.default_print_stock_label);
if (productDetails.product.allow_label_per_unit)
{
if ($('#default_print_stock_label').val() == "2")
{
$("#default_print_stock_label").val("0");
}
$('#label-option-per-unit').prop("disabled", true);
}
else
{
$('#label-option-per-unit').prop("disabled", false);
}
}
$("#display_amount").focus();
Grocy.FrontendHelpers.ValidateForm('purchase-form');

View File

@@ -124,6 +124,21 @@ $(document).on("click", ".stock-name-cell", function(e)
$("#stockentry-productcard-modal").modal("show");
});
$(document).on('click', '.stockentry-grocycode-stockentry-label-print', function(e)
{
e.preventDefault();
document.activeElement.blur();
var stockId = $(e.currentTarget).attr('data-stock-id');
Grocy.Api.Get('stock/entry/' + stockId + '/printlabel', function(labelData)
{
if (Grocy.Webhooks.labelprinter !== undefined)
{
Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, labelData);
}
});
});
function RefreshStockEntryRow(stockRowId)
{
Grocy.Api.Get("stock/entry/" + stockRowId,

View File

@@ -101,6 +101,21 @@ $("#search").on("keyup", Delay(function()
stockOverviewTable.search(value).draw();
}, 200));
$(document).on('click', '.stockentry-grocycode-product-label-print', function(e)
{
e.preventDefault();
document.activeElement.blur();
var productId = $(e.currentTarget).attr('data-product-id');
Grocy.Api.Get('stock/products/' + productId + '/printlabel', function(labelData)
{
if (Grocy.Webhooks.labelprinter !== undefined)
{
Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, labelData);
}
});
});
$(document).on('click', '.product-consume-button', function(e)
{
e.preventDefault();