From 948c9c1d23f2c84e8afe1f553c2fdd102439dde1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 6 Apr 2020 22:13:57 +1000 Subject: [PATCH] Further improvements for stock view --- lib/inventree/stock.dart | 53 ++++++++++++++++++- lib/widget/part_display.dart | 9 ++-- lib/widget/stock_display.dart | 97 +++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 4 deletions(-) diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 450a20cf..60aaaecd 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -15,6 +15,7 @@ class InvenTreeStockItem extends InvenTreeModel { headers["part_detail"] = "true"; headers["location_detail"] = "true"; + headers["supplier_detail"] = "true"; return headers; } @@ -25,6 +26,10 @@ class InvenTreeStockItem extends InvenTreeModel { // TODO } + int get partId => jsondata['part'] ?? -1; + + int get trackingItemCount => jsondata['tracking_items'] as int ?? 0; + String get partName { String nm = ''; @@ -78,12 +83,58 @@ class InvenTreeStockItem extends InvenTreeModel { return thumb; } + int get supplierPartId => jsondata['supplier_part'] as int ?? -1; + + String get supplierImage { + String thumb = ''; + + if (jsondata.containsKey("supplier_detail")) { + thumb = jsondata['supplier_detail']['supplier_logo'] ?? ''; + } + + return thumb; + } + + String get supplierName { + String sname = ''; + + if (jsondata.containsKey("supplier_detail")) { + sname = jsondata["supplier_detail"]["supplier_name"] ?? ''; + } + + return sname; + } + + String get supplierSKU { + String sku = ''; + + if (jsondata.containsKey("supplier_detail")) { + sku = jsondata["supplier_detail"]["SKU"] ?? ''; + } + + return sku; + } + int get serialNumber => jsondata['serial'] as int ?? null; - double get quantity => jsondata['quantity'] as double ?? 0.0; + double get quantity => double.tryParse(jsondata['quantity'].toString() ?? '0'); int get locationId => jsondata['location'] as int ?? -1; + String get locationName { + String loc = ''; + + if (jsondata.containsKey('location_detail')) { + loc = jsondata['location_detail']['name'] ?? ''; + } + + if (loc.isEmpty) { + loc = jsondata['location__name'] ?? ''; + } + + return loc; + } + String get displayQuantity { // Display either quantity or serial number! diff --git a/lib/widget/part_display.dart b/lib/widget/part_display.dart index 327040d7..d987d91b 100644 --- a/lib/widget/part_display.dart +++ b/lib/widget/part_display.dart @@ -61,9 +61,12 @@ class _PartDisplayState extends State { subtitle: Text("${part.categoryName}"), leading: FaIcon(FontAwesomeIcons.stream), onTap: () { - InvenTreePartCategory().get(part.categoryId).then((var cat) { - Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(cat))); - }); + if (part.categoryId > 0) { + InvenTreePartCategory().get(part.categoryId).then((var cat) { + Navigator.push(context, MaterialPageRoute( + builder: (context) => CategoryDisplayWidget(cat))); + }); + } }, ) ); diff --git a/lib/widget/stock_display.dart b/lib/widget/stock_display.dart index 5bce2bde..6a4c5938 100644 --- a/lib/widget/stock_display.dart +++ b/lib/widget/stock_display.dart @@ -1,6 +1,9 @@ import 'package:InvenTree/inventree/stock.dart'; +import 'package:InvenTree/inventree/part.dart'; +import 'package:InvenTree/widget/location_display.dart'; +import 'package:InvenTree/widget/part_display.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -52,6 +55,100 @@ class _StockItemDisplayState extends State { ) ); + tiles.add( + ListTile( + title: Text("Part"), + subtitle: Text("${item.partName}"), + leading: FaIcon(FontAwesomeIcons.shapes), + onTap: () { + if (item.partId > 0) { + InvenTreePart().get(item.partId).then((var part) { + if (part is InvenTreePart) { + Navigator.push(context, MaterialPageRoute(builder: (context) => PartDisplayWidget(part))); + } + }); + } + }, + ) + ); + + // Quantity information + tiles.add( + ListTile( + title: Text("Quantity"), + leading: FaIcon(FontAwesomeIcons.cubes), + trailing: Text("${item.quantity}"), + ) + ); + + // Location information + if (item.locationName.isNotEmpty) { + tiles.add( + ListTile( + title: Text("Stock Location"), + subtitle: Text("${item.locationName}"), + leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), + onTap: () { + if (item.locationId > 0) { + InvenTreeStockLocation().get(item.locationId).then((var loc) { + Navigator.push(context, MaterialPageRoute( + builder: (context) => LocationDisplayWidget(loc))); + }); + } + }, + ) + ); + } + + // Supplier part? + if (item.supplierPartId > 0) { + tiles.add( + ListTile( + title: Text("${item.supplierName}"), + subtitle: Text("${item.supplierSKU}"), + leading: FaIcon(FontAwesomeIcons.industry), + trailing: Image( + image: InvenTreeAPI().getImage(item.supplierImage), + height: 32, + ), + onTap: null, + ) + ); + } + + if (item.link.isNotEmpty) { + tiles.add( + ListTile( + title: Text("${item.link}"), + leading: FaIcon(FontAwesomeIcons.link), + trailing: Text(""), + onTap: null, + ) + ); + } + + if (item.trackingItemCount > 0) { + tiles.add( + ListTile( + title: Text("History"), + leading: FaIcon(FontAwesomeIcons.history), + trailing: Text("${item.trackingItemCount}"), + onTap: null, + ) + ); + } + + if (item.notes.isNotEmpty) { + tiles.add( + ListTile( + title: Text("Notes"), + leading: FaIcon(FontAwesomeIcons.stickyNote), + trailing: Text(""), + onTap: null, + ) + ); + } + return tiles; }