From 013e9770313615e1059a7de81f421f2cd388abc8 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 2 Aug 2021 14:00:39 +1000 Subject: [PATCH] Request list of supplierparts --- lib/inventree/part.dart | 25 ++++++++++++++++++++++++- lib/widget/part_detail.dart | 4 +--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index d41ee1e7..d8d8e8c2 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -165,7 +165,30 @@ class InvenTreePart extends InvenTreeModel { }); } - int get supplier_count => (jsondata['suppliers'] ?? 0) as int; + int get supplierCount => (jsondata['suppliers'] ?? 0) as int; + + // Request supplier parts for this part + Future> getSupplierParts() async { + List _supplierParts = []; + + final parts = await InvenTreeSupplierPart().list( + filters: { + "part": "${pk}", + "manufacturer_detail": "true", + "supplier_detail": "true", + "supplier_part_detail": "true" + } + ); + + for (result in parts) { + if (result is InvenTreeSupplierPart) { + _supplierParts.add(result); + } + } + + return _supplierParts; + } + // Cached list of test templates List testingTemplates = []; diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 5eaa8d65..e00e2fb8 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -325,13 +325,11 @@ class _PartDisplayState extends RefreshableState { // Tiles for "purchaseable" parts if (part.isPurchaseable) { - // Suppliers (TODO) - if (part.supplier_count > 0) { tiles.add( ListTile( title: Text(L10().suppliers), leading: FaIcon(FontAwesomeIcons.industry), - trailing: Text("${part.supplier_count}"), + trailing: Text("${part.supplierCount}"), onTap: () { // TODO },