2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 19:50:59 +00:00

Stock API filtering fix (#4350)

* Improve filtering options for StockItem list

- Make use of StockFilter introspection

* Remove outdated filter

* remove outdated "max_results" parameter

* Fix cascade issue for stocklist API

* Add relationship filters to the StockItemFilter

* Fix filtering by 'status' and 'allocated'

* Refactor 'customer' and 'expired' filters

* Cleanup

* Adds unit test for top-level stock location filtering
This commit is contained in:
Oliver
2023-02-17 10:34:18 +11:00
committed by GitHub
parent b02ce1f01e
commit 6627a8097b
5 changed files with 108 additions and 165 deletions

View File

@ -306,6 +306,29 @@ class StockItemListTest(StockAPITestCase):
# Return JSON-ified data
return response.data
def test_top_level_filtering(self):
"""Test filtering against "top level" stock location"""
# No filters, should return *all* items
response = self.get(self.list_url, {}, expected_code=200)
self.assertEqual(len(response.data), StockItem.objects.count())
# Filter with "cascade=False" (but no location specified)
# Should not result in any actual filtering
response = self.get(self.list_url, {'cascade': False}, expected_code=200)
self.assertEqual(len(response.data), StockItem.objects.count())
# Filter with "cascade=False" for the top-level location
response = self.get(self.list_url, {'location': 'null', 'cascade': False}, expected_code=200)
self.assertTrue(len(response.data) < StockItem.objects.count())
for result in response.data:
self.assertIsNone(result['location'])
# Filter with "cascade=True"
response = self.get(self.list_url, {'location': 'null', 'cascade': True}, expected_code=200)
self.assertEqual(len(response.data), StockItem.objects.count())
def test_get_stock_list(self):
"""List *all* StockItem objects."""
response = self.get_stock()