From 4d1eb51bc429a50110ae5a4779fa6809472bc282 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 20 Apr 2021 20:42:55 +1000 Subject: [PATCH] Fixes --- InvenTree/part/api.py | 5 ++++- InvenTree/part/test_api.py | 44 +++++++++++++++++++++++++++++++++++++- InvenTree/stock/api.py | 5 ++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 0ce7c7d5a6..a2d7609bed 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -74,8 +74,11 @@ class CategoryList(generics.ListCreateAPIView): cascade = str2bool(params.get('cascade', False)) + # Do not filter by category + if cat_id is None: + pass # Look for top-level categories - if isNull(cat_id): + elif isNull(cat_id): if not cascade: queryset = queryset.filter(parent=None) diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index ed88e1dd55..4389003544 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -37,12 +37,54 @@ class PartAPITest(InvenTreeAPITestCase): super().setUp() def test_get_categories(self): - """ Test that we can retrieve list of part categories """ + """ + Test that we can retrieve list of part categories, + with various filtering options. + """ + url = reverse('api-part-category-list') + + # Request *all* part categories response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 8) + # Request top-level part categories only + response = self.client.get( + url, + { + 'parent': 'null', + }, + format='json' + ) + + self.assertEqual(len(response.data), 2) + + # Children of PartCategory<1>, cascade + response = self.client.get( + url, + { + 'parent': 1, + 'cascade': 'true', + }, + format='json', + ) + + self.assertEqual(len(response.data), 5) + + # Children of PartCategory<1>, do not cascade + response = self.client.get( + url, + { + 'parent': 1, + 'cascade': 'false', + }, + format='json', + ) + + self.assertEqual(len(response.data), 3) + def test_add_categories(self): """ Check that we can add categories """ data = { diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index a76fd801bd..0e64cecdbd 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -295,8 +295,11 @@ class StockLocationList(generics.ListCreateAPIView): cascade = str2bool(params.get('cascade', False)) + # Do not filter by location + if loc_id is None: + pass # Look for top-level locations - if isNull(loc_id): + elif isNull(loc_id): # If we allow "cascade" at the top-level, this essentially means *all* locations if not cascade: