mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +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:
		| @@ -1,6 +1,7 @@ | |||||||
| ### 0.17.2 - December 2024 | ### 0.17.2 - December 2024 | ||||||
| --- | --- | ||||||
|  |  | ||||||
|  | - Fixed error message when printing a label to a remote machine | ||||||
| - Prevent notification sounds from pause media playback | - Prevent notification sounds from pause media playback | ||||||
| - Updated translations | - Updated translations | ||||||
|  |  | ||||||
|   | |||||||
| @@ -817,6 +817,11 @@ class InvenTreeAPI { | |||||||
|    */ |    */ | ||||||
|   Future<void> downloadFile(String url, {bool openOnDownload = true}) async { |   Future<void> downloadFile(String url, {bool openOnDownload = true}) async { | ||||||
|  |  | ||||||
|  |     if (url.isEmpty) { | ||||||
|  |       // No URL provided for download | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // Find the local downlods directory |     // Find the local downlods directory | ||||||
|     final Directory dir = await getTemporaryDirectory(); |     final Directory dir = await getTemporaryDirectory(); | ||||||
|  |  | ||||||
| @@ -1538,7 +1543,7 @@ class InvenTreeAPI { | |||||||
|       return setting.value; |       return setting.value; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     final response = await InvenTreeGlobalSetting().getModel(key); |     final response = await InvenTreeUserSetting().getModel(key); | ||||||
|  |  | ||||||
|     if (response is InvenTreeUserSetting) { |     if (response is InvenTreeUserSetting) { | ||||||
|       response.lastReload = DateTime.now(); |       response.lastReload = DateTime.now(); | ||||||
|   | |||||||
| @@ -904,7 +904,7 @@ class InvenTreeUserSetting extends InvenTreeGlobalSetting { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) { |   InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) { | ||||||
|     return InvenTreeGlobalSetting.fromJson(json); |     return InvenTreeUserSetting.fromJson(json); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @override |   @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"]; |     initial_plugin = plugin_options.first["value"]; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -111,27 +115,29 @@ Future<void> selectAndPrintLabel( | |||||||
|               "items": [instanceId] |               "items": [instanceId] | ||||||
|             } |             } | ||||||
|           ).then((APIResponse response) { |           ).then((APIResponse response) { | ||||||
|             hideLoadingOverlay(); |  | ||||||
|  |  | ||||||
|             if (response.isValid() && response.statusCode >= 200 && |             if (response.isValid() && response.statusCode >= 200 && | ||||||
|                 response.statusCode <= 201) { |                 response.statusCode <= 201) { | ||||||
|               var data = response.asMap(); |               var data = response.asMap(); | ||||||
|  |  | ||||||
|               if (data.containsKey("output")) { |               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; |                 result = true; | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|       } else { |  | ||||||
|  |         } else { | ||||||
|           // Legacy label printing API |           // Legacy label printing API | ||||||
|           // Uses a GET request to a specially formed URL which depends on the parameters |           // Uses a GET request to a specially formed URL which depends on the parameters | ||||||
|           String url = "/label/${labelType}/${labelId}/print/?${labelQuery}&plugin=${pluginKey}"; |           String url = "/label/${labelType}/${labelId}/print/?${labelQuery}&plugin=${pluginKey}"; | ||||||
|           await InvenTreeAPI().get(url).then((APIResponse response) { |           await InvenTreeAPI().get(url).then((APIResponse response) { | ||||||
|             hideLoadingOverlay(); |  | ||||||
|             if (response.isValid() && response.statusCode == 200) { |             if (response.isValid() && response.statusCode == 200) { | ||||||
|               var data = response.asMap(); |               var data = response.asMap(); | ||||||
|               if (data.containsKey("file")) { |               if (data.containsKey("file")) { | ||||||
| @@ -145,6 +151,8 @@ Future<void> selectAndPrintLabel( | |||||||
|           }); |           }); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |       hideLoadingOverlay(); | ||||||
|  |  | ||||||
|       if (result) { |       if (result) { | ||||||
|         showSnackIcon( |         showSnackIcon( | ||||||
|           L10().printLabelSuccess, |           L10().printLabelSuccess, | ||||||
|   | |||||||
| @@ -66,5 +66,7 @@ void showLoadingOverlay() { | |||||||
|  |  | ||||||
|  |  | ||||||
| void hideLoadingOverlay() { | void hideLoadingOverlay() { | ||||||
|   Loader.hide(); |   if (Loader.isShown) { | ||||||
|  |     Loader.hide(); | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user