2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-02 13:28:49 +00:00

Bug fix: distinct query (#5960)

- Fixes bug inroduced in https://github.com/inventree/InvenTree/pull/5917
This commit is contained in:
Oliver 2023-11-21 22:47:02 +11:00 committed by GitHub
parent 1d05e8d4e3
commit efaea8f7eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -66,17 +66,16 @@ class GeneralExtraLineList(APIDownloadMixin):
filter_backends = SEARCH_ORDER_FILTER filter_backends = SEARCH_ORDER_FILTER
ordering_fields = [ ordering_fields = [
'title',
'quantity', 'quantity',
'note', 'note',
'reference', 'reference',
] ]
search_fields = [ search_fields = [
'title',
'quantity', 'quantity',
'note', 'note',
'reference' 'reference',
'description',
] ]
filterset_fields = [ filterset_fields = [

View File

@ -996,8 +996,8 @@ class StockList(APIDownloadMixin, ListCreateDestroyAPIView):
if company is not None: if company is not None:
queryset = queryset.filter( 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 return queryset

View File

@ -404,6 +404,11 @@ class StockItemListTest(StockAPITestCase):
response = self.get_stock(batch='B123') response = self.get_stock(batch='B123')
self.assertEqual(len(response), 1) 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): def test_filter_by_serialized(self):
"""Filter StockItem by serialized status.""" """Filter StockItem by serialized status."""
response = self.get_stock(serialized=1) response = self.get_stock(serialized=1)
@ -658,10 +663,10 @@ class StockItemListTest(StockAPITestCase):
def test_query_count(self): def test_query_count(self):
"""Test that the number of queries required to fetch stock items is reasonable.""" """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.""" """Helper function to fetch stock items."""
response = self.client.get(self.list_url, data=data) 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 return response.data
# Create a bunch of StockItem objects # Create a bunch of StockItem objects