2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 10:45:29 +00:00

Label printing fix (#587)

* Handle blank URL provided for file download

* Improved printing checks

* Auto-select the correct printer
This commit is contained in:
Oliver
2024-12-23 09:57:13 +11:00
committed by GitHub
parent dc8191c3d8
commit bc44b99d43
5 changed files with 26 additions and 10 deletions

View File

@ -63,7 +63,11 @@ Future<void> selectAndPrintLabel(
});
}
if (plugin_options.length == 1) {
String selectedPlugin = await InvenTreeAPI().getUserSetting("LABEL_DEFAULT_PRINTER");
if (selectedPlugin.isNotEmpty) {
initial_plugin = selectedPlugin;
} else if (plugin_options.length == 1) {
initial_plugin = plugin_options.first["value"];
}
@ -111,27 +115,29 @@ Future<void> selectAndPrintLabel(
"items": [instanceId]
}
).then((APIResponse response) {
hideLoadingOverlay();
if (response.isValid() && response.statusCode >= 200 &&
response.statusCode <= 201) {
var data = response.asMap();
if (data.containsKey("output")) {
var label_file = (data["output"] ?? "") as String;
String? label_file = (data["output"]) as String?;
if (label_file != null && label_file.isNotEmpty) {
// Attempt to open generated file
InvenTreeAPI().downloadFile(label_file);
}
// Attempt to open generated file
InvenTreeAPI().downloadFile(label_file);
result = true;
}
}
});
} else {
} else {
// Legacy label printing API
// Uses a GET request to a specially formed URL which depends on the parameters
String url = "/label/${labelType}/${labelId}/print/?${labelQuery}&plugin=${pluginKey}";
await InvenTreeAPI().get(url).then((APIResponse response) {
hideLoadingOverlay();
if (response.isValid() && response.statusCode == 200) {
var data = response.asMap();
if (data.containsKey("file")) {
@ -145,6 +151,8 @@ Future<void> selectAndPrintLabel(
});
}
hideLoadingOverlay();
if (result) {
showSnackIcon(
L10().printLabelSuccess,