From a889c4adbe4d56a780ece4a0f5f5c0a116d84601 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 28 Feb 2024 16:23:46 +1100 Subject: [PATCH] Filter fix (#473) * Add check for "null" top level locations and categories * Fix API - Top level location and category broken after API 174 - Ref: https://github.com/inventree/InvenTree/pull/6536 --- assets/release_notes.md | 4 +++- lib/api.dart | 3 +++ lib/widget/part/category_display.dart | 14 +++++++++++--- lib/widget/stock/location_display.dart | 15 ++++++++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index 11731db0..a920d6aa 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -1,7 +1,9 @@ -### 0.14.2 - January 2024 +### 0.14.2 - February 2024 --- - Updated error reporting +- Support for updated server API endpoints +- Updated translations ### 0.14.1 - January 2024 --- diff --git a/lib/api.dart b/lib/api.dart index 3d91da88..7028bea0 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -339,6 +339,9 @@ class InvenTreeAPI { // Does the server support allocating stock to sales order using barcodes? bool get supportsBarcodeSOAllocateEndpoint => isConnected() && apiVersion >= 160; + // Does the server support "null" top-level filtering for PartCategory and StockLocation endpoints? + bool get supportsNullTopLevelFiltering => isConnected() && apiVersion < 174; + // Cached list of plugins (refreshed when we connect to the server) List _plugins = []; diff --git a/lib/widget/part/category_display.dart b/lib/widget/part/category_display.dart index c399cef5..35be18cb 100644 --- a/lib/widget/part/category_display.dart +++ b/lib/widget/part/category_display.dart @@ -200,13 +200,21 @@ class _CategoryDisplayState extends RefreshableState { // Construct the "details" panel List detailTiles() { + Map filters = {}; + + int? parent = widget.category?.pk; + + if (parent != null) { + filters["parent"] = parent.toString(); + } else if (api.supportsNullTopLevelFiltering) { + filters["parent"] = "null"; + } + List tiles = [ getCategoryDescriptionCard(), Expanded( child: PaginatedPartCategoryList( - { - "parent": widget.category?.pk.toString() ?? "null" - }, + filters, title: L10().subcategories, ), flex: 10, diff --git a/lib/widget/stock/location_display.dart b/lib/widget/stock/location_display.dart index 8b6a9122..f31940c0 100644 --- a/lib/widget/stock/location_display.dart +++ b/lib/widget/stock/location_display.dart @@ -393,13 +393,22 @@ class _LocationDisplayState extends RefreshableState { // Construct the "details" panel List detailTiles() { + + Map filters = {}; + + int? parent = location?.pk; + + if (parent != null) { + filters["parent"] = parent.toString(); + } else if (api.supportsNullTopLevelFiltering) { + filters["parent"] = "null"; + } + List tiles = [ locationDescriptionCard(), Expanded( child: PaginatedStockLocationList( - { - "parent": location?.pk.toString() ?? "null", - }, + filters, title: L10().sublocations, ), flex: 10,