From 56bdf83692069908f4aebd07c27c34a3380f9465 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 30 May 2020 21:09:31 +1000 Subject: [PATCH] More complex lookup --- lib/inventree/stock.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 2b137cd0..cccec527 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -180,6 +180,11 @@ class InvenTreeStockItem extends InvenTreeModel { nm = jsondata['part_detail']['full_name'] ?? ''; } + // Backup if first value fails + if (nm.isEmpty) { + nm = jsondata['part__name'] ?? ''; + } + return nm; } @@ -212,9 +217,23 @@ class InvenTreeStockItem extends InvenTreeModel { return img; } + /** + * Return the Part thumbnail for this stock item. + */ String get partThumbnail { - String thumb = jsondata['part__thumbnail'] as String ?? ''; + String thumb; + + if (jsondata.containsKey('part_detail')) { + thumb = jsondata['part_detail']['thumbnail'] as String ?? ''; + } + + // Try a different approach + if (thumb.isEmpty) { + jsondata['part__thumbnail'] as String ?? ''; + } + + // Still no thumbnail? Use the 'no image' image if (thumb.isEmpty) thumb = InvenTreeAPI.staticThumb; return thumb;