mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 13:25:40 +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:
		| @@ -817,6 +817,11 @@ class InvenTreeAPI { | ||||
|    */ | ||||
|   Future<void> downloadFile(String url, {bool openOnDownload = true}) async { | ||||
|  | ||||
|     if (url.isEmpty) { | ||||
|       // No URL provided for download | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     // Find the local downlods directory | ||||
|     final Directory dir = await getTemporaryDirectory(); | ||||
|  | ||||
| @@ -1538,7 +1543,7 @@ class InvenTreeAPI { | ||||
|       return setting.value; | ||||
|     } | ||||
|  | ||||
|     final response = await InvenTreeGlobalSetting().getModel(key); | ||||
|     final response = await InvenTreeUserSetting().getModel(key); | ||||
|  | ||||
|     if (response is InvenTreeUserSetting) { | ||||
|       response.lastReload = DateTime.now(); | ||||
|   | ||||
| @@ -904,7 +904,7 @@ class InvenTreeUserSetting extends InvenTreeGlobalSetting { | ||||
|  | ||||
|   @override | ||||
|   InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) { | ||||
|     return InvenTreeGlobalSetting.fromJson(json); | ||||
|     return InvenTreeUserSetting.fromJson(json); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -66,5 +66,7 @@ void showLoadingOverlay() { | ||||
|  | ||||
|  | ||||
| void hideLoadingOverlay() { | ||||
|   Loader.hide(); | ||||
|   if (Loader.isShown) { | ||||
|     Loader.hide(); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user