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:
parent
1d05e8d4e3
commit
efaea8f7eb
@ -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 = [
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user