diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 738dda6f..c681fcab 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -125,6 +125,7 @@ class InvenTreeStockItem extends InvenTreeModel { headers["part_detail"] = "true"; headers["location_detail"] = "true"; headers["supplier_detail"] = "true"; + headers["cascade"] = "false"; return headers; } diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 76b9d562..59570b1e 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -229,7 +229,7 @@ class _LocationDisplayState extends RefreshableState { children: detailTiles(), ); case 1: - return PaginatedStockList(location?.pk ?? null); + return PaginatedStockList({"location": "${location?.pk ?? -1}"}); case 2: return ListView( children: ListTile.divideTiles( @@ -401,12 +401,12 @@ class SublocationList extends StatelessWidget { class PaginatedStockList extends StatefulWidget { - final int locationId; + final Map filters; - PaginatedStockList(this.locationId); + PaginatedStockList(this.filters); @override - _PaginatedStockListState createState() => _PaginatedStockListState(locationId); + _PaginatedStockListState createState() => _PaginatedStockListState(filters); } @@ -416,9 +416,9 @@ class _PaginatedStockListState extends State { String _searchTerm; - final int locationId; + final Map filters; - _PaginatedStockListState(this.locationId); + _PaginatedStockListState(this.filters); final PagingController _pagingController = PagingController(firstPageKey: 0); @@ -440,15 +440,13 @@ class _PaginatedStockListState extends State { Future _fetchPage(int pageKey) async { try { - Map filters = { - "location": "${locationId}" - }; + Map params = this.filters; if (_searchTerm != null && _searchTerm.isNotEmpty) { - filters["search"] = "${_searchTerm}"; + params["search"] = "${_searchTerm}"; } - final page = await InvenTreeStockItem().listPaginated(_pageSize, pageKey, filters: filters); + final page = await InvenTreeStockItem().listPaginated(_pageSize, pageKey, filters: params); final isLastPage = page.length < _pageSize; // Construct a list of stock item objects diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index ed661ff5..8da38ffc 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -19,6 +19,8 @@ import 'package:InvenTree/widget/fields.dart'; import 'package:InvenTree/api.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; +import 'location_display.dart'; + class PartDetailWidget extends StatefulWidget { @@ -88,7 +90,6 @@ class _PartDisplayState extends RefreshableState { @override Future request(BuildContext context) async { await part.reload(context); - await part.getStockItems(context); await part.getTestTemplates(context); } @@ -390,11 +391,13 @@ class _PartDisplayState extends RefreshableState { ) ); + /* if (loading) { tiles.add(progressIndicator()); } else if (part.stockItems.length > 0) { tiles.add(PartStockList(part.stockItems)); } + */ return tiles; } @@ -437,6 +440,8 @@ class _PartDisplayState extends RefreshableState { ), ); case 1: + return PaginatedStockList({"part": "${part.pk}"}); + /* return Center( child: ListView( children: ListTile.divideTiles( @@ -445,6 +450,7 @@ class _PartDisplayState extends RefreshableState { ).toList() ) ); + */ case 2: return Center( child: ListView( @@ -488,45 +494,4 @@ class _PartDisplayState extends RefreshableState { Widget getBody(BuildContext context) { return getSelectedWidget(tabIndex); } -} - -class PartStockList extends StatelessWidget { - final List _items; - - PartStockList(this._items); - - void _openItem(BuildContext context, int pk) { - // Load detail view for stock item - InvenTreeStockItem().get(context, pk).then((var item) { - if (item is InvenTreeStockItem) { - Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item))); - } - }); - } - - Widget _build(BuildContext context, int index) { - - InvenTreeStockItem item = _items[index]; - - return ListTile( - title: Text("${item.locationName}"), - subtitle: Text("${item.locationPathString}"), - trailing: Text(item.serialOrQuantityDisplay()), - leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), - onTap: () { - _openItem(context, item.pk); - }, - ); - } - - @override - Widget build(BuildContext context) { - return ListView.separated( - shrinkWrap: true, - physics: ClampingScrollPhysics(), - itemBuilder: _build, - separatorBuilder: (_, __) => const Divider(height: 3), - itemCount: _items.length - ); - } } \ No newline at end of file