From 04b09b55911bb90c11d5e7546df2a1c1fb562c7f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 8 Apr 2020 12:18:50 +1000 Subject: [PATCH] Display either serial number or quantity depending on stock properties --- lib/inventree/stock.dart | 2 ++ lib/widget/stock_detail.dart | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 2365b74b..5336ff33 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -121,6 +121,8 @@ class InvenTreeStockItem extends InvenTreeModel { int get locationId => jsondata['location'] as int ?? -1; + bool isSerialized() => serialNumber != null && quantity.toInt() == 1; + String get locationName { String loc = ''; diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index ab4a7225..b770d89f 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -74,13 +74,25 @@ class _StockItemDisplayState extends State { ); // Quantity information - tiles.add( - ListTile( - title: Text("Quantity"), - leading: FaIcon(FontAwesomeIcons.cubes), - trailing: Text("${item.quantity}"), - ) - ); + if (item.isSerialized()) { + tiles.add( + ListTile( + title: Text("Serial Number"), + leading: FaIcon(FontAwesomeIcons.hashtag), + trailing: Text("${item.serialNumber}"), + ) + ); + } else { + tiles.add( + ListTile( + title: Text("Quantity"), + leading: FaIcon(FontAwesomeIcons.cubes), + trailing: Text("${item.quantity}"), + ) + ); + + } + // Location information if (item.locationName.isNotEmpty) {