diff --git a/lib/api.dart b/lib/api.dart index 44f7f636..9c13f9fe 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -333,6 +333,7 @@ class InvenTreeAPI { // Default API version is 1 if not provided _apiVersion = (data["apiVersion"] ?? 1) as int; + _pluginsEnabled = (data["plugins_enabled"] ?? false) as bool; if (_apiVersion < _minApiVersion) { @@ -347,14 +348,12 @@ class InvenTreeAPI { showServerError( L10().serverOld, - message + message, ); return false; } - _pluginsEnabled = (data["plugins_enabled"] ?? false) as bool; - /** * Request user token information from the server * This is the stage that we check username:password credentials! diff --git a/lib/l10n b/lib/l10n index 2396ebd4..8717eeeb 160000 --- a/lib/l10n +++ b/lib/l10n @@ -1 +1 @@ -Subproject commit 2396ebd447a616b5eebddd8d4ee407253d678d2f +Subproject commit 8717eeeb0d2ac2d406aec95cd9d0fcdf8609eb23 diff --git a/lib/widget/purchase_order_detail.dart b/lib/widget/purchase_order_detail.dart index 169a82b8..d6cdfea2 100644 --- a/lib/widget/purchase_order_detail.dart +++ b/lib/widget/purchase_order_detail.dart @@ -227,6 +227,8 @@ class _PurchaseOrderDetailState extends RefreshableState children = []; + // TODO: Add in this option once the SupplierPart detail view is implemented + /* children.add( SimpleDialogOption( onPressed: () { @@ -240,6 +242,7 @@ class _PurchaseOrderDetailState extends RefreshableState { // StockItem object final InvenTreeStockItem item; + // Is label printing enabled for this StockItem? + // This will be determined when the widget is loaded + List> labels = []; + // Part object InvenTreePart? part; @@ -103,8 +107,41 @@ class _StockItemDisplayState extends RefreshableState { // Request part information part = await InvenTreePart().get(item.partId) as InvenTreePart?; - // Request test results... - await item.getTestResults(); + // Request test results (async) + item.getTestResults().then((value) { + setState(() { + // Update + }); + }); + + // Request information on labels available for this stock item + if (InvenTreeAPI().pluginsEnabled()) { + _getLabels(); + } + } + + Future _getLabels() async { + // Clear the existing labels list + labels.clear(); + + InvenTreeAPI().get( + "/label/stock/", + params: { + "enabled": "true", + "item": "${item.pk}", + }, + ).then((APIResponse response) { + if (response.isValid() && response.statusCode == 200) { + for (var label in response.data) { + if (label is Map) { + labels.add(label); + } + } + + setState(() { + }); + } + }); } Future _editStockItem(BuildContext context) async { @@ -859,6 +896,19 @@ class _StockItemDisplayState extends RefreshableState { ); } + // Print label (if label printing plugins exist) + if (labels.isNotEmpty) { + tiles.add( + ListTile( + title: Text(L10().printLabel), + leading: FaIcon(FontAwesomeIcons.print, color: COLOR_CLICK), + onTap: () { + // TODO + }, + ), + ); + } + return tiles; }