From efaea8f7ebcba45bc0f097501d5c3937a5ce8e21 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 21 Nov 2023 22:47:02 +1100 Subject: [PATCH] Bug fix: distinct query (#5960) - Fixes bug inroduced in https://github.com/inventree/InvenTree/pull/5917 --- InvenTree/order/api.py | 5 ++--- InvenTree/stock/api.py | 4 ++-- InvenTree/stock/test_api.py | 9 +++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index b4a60a95ae..6c21fe0af5 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -66,17 +66,16 @@ class GeneralExtraLineList(APIDownloadMixin): filter_backends = SEARCH_ORDER_FILTER ordering_fields = [ - 'title', 'quantity', 'note', 'reference', ] search_fields = [ - 'title', 'quantity', 'note', - 'reference' + 'reference', + 'description', ] filterset_fields = [ diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index c8ffb579cc..62ac3cf465 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -996,8 +996,8 @@ class StockList(APIDownloadMixin, ListCreateDestroyAPIView): if company is not None: queryset = queryset.filter( - Q(supplier_part__supplier=company) | Q(supplier_part__manufacturer_part__manufacturer=company).distinct() - ) + Q(supplier_part__supplier=company) | Q(supplier_part__manufacturer_part__manufacturer=company) + ).distinct() return queryset diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index 1f2e54a07e..382d3683c9 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -404,6 +404,11 @@ class StockItemListTest(StockAPITestCase): response = self.get_stock(batch='B123') self.assertEqual(len(response), 1) + def test_filter_by_company(self): + """Test that we can filter stock items by company""" + for cmp in company.models.Company.objects.all(): + self.get_stock(company=cmp.pk) + def test_filter_by_serialized(self): """Filter StockItem by serialized status.""" response = self.get_stock(serialized=1) @@ -658,10 +663,10 @@ class StockItemListTest(StockAPITestCase): def test_query_count(self): """Test that the number of queries required to fetch stock items is reasonable.""" - def get_stock(data): + def get_stock(data, expected_status=200): """Helper function to fetch stock items.""" response = self.client.get(self.list_url, data=data) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, expected_status) return response.data # Create a bunch of StockItem objects