diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 46b0c75a..0bc826fb 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -451,7 +451,14 @@ class InvenTreeStockItem extends InvenTreeModel { String quantityString({bool includeUnits = false}){ - String q = simpleNumberString(quantity); + String q = ""; + + if (allocated > 0) { + q += simpleNumberString(available); + q += " / "; + } + + q += simpleNumberString(quantity); if (includeUnits && units.isNotEmpty) { q += " ${units}"; @@ -460,6 +467,10 @@ class InvenTreeStockItem extends InvenTreeModel { return q; } + double get allocated => double.tryParse(jsondata["allocated"].toString()) ?? 0; + + double get available => quantity - allocated; + int get locationId => (jsondata["location"] ?? -1) as int; bool isSerialized() => serialNumber.isNotEmpty && quantity.toInt() == 1; @@ -467,9 +478,11 @@ class InvenTreeStockItem extends InvenTreeModel { String serialOrQuantityDisplay() { if (isSerialized()) { return "SN ${serialNumber}"; + } else if (allocated > 0) { + return "${available} / ${quantity}"; + } else { + return simpleNumberString(quantity); } - - return simpleNumberString(quantity); } String get locationName { diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 83db3d4b..8183af6b 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -655,6 +655,9 @@ "description": "Quantity" }, + "quantityAvailable": "Quantity Available", + "@quantityAvailable": {}, + "quantityEmpty": "Quantity is empty", "@quantityEmpty": {}, diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index d8c43adb..85121036 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -513,7 +513,7 @@ class _StockItemDisplayState extends RefreshableState { } else { tiles.add( ListTile( - title: Text(L10().quantity), + title: item.allocated > 0 ? Text(L10().quantityAvailable) : Text(L10().quantity), leading: FaIcon(FontAwesomeIcons.cubes), trailing: Text("${item.quantityString()}"), )