mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Part API Filter Fix (#3271)
* Fix API filter 'in_bom_for' - get_parts_in_bom() returns a list, not a queryset - Thus, we have to enumerate the ID values, rather than filtering by queryset * Add unit test for part API filter
This commit is contained in:
parent
26d5d15b49
commit
825e4b4cd8
@ -866,7 +866,8 @@ class PartFilter(rest_filters.FilterSet):
|
||||
def filter_in_bom(self, queryset, name, part):
|
||||
"""Limit queryset to parts in the BOM for the specified part"""
|
||||
|
||||
queryset = queryset.filter(id__in=part.get_parts_in_bom())
|
||||
bom_parts = part.get_parts_in_bom()
|
||||
queryset = queryset.filter(id__in=[p.pk for p in bom_parts])
|
||||
return queryset
|
||||
|
||||
is_template = rest_filters.BooleanFilter()
|
||||
|
@ -400,6 +400,21 @@ class PartAPITest(InvenTreeAPITestCase):
|
||||
for part in response.data:
|
||||
self.assertEqual(part['category'], 2)
|
||||
|
||||
def test_filter_by_in_bom(self):
|
||||
"""Test that we can filter part list by the 'in_bom_for' parameter"""
|
||||
|
||||
url = reverse('api-part-list')
|
||||
|
||||
response = self.get(
|
||||
url,
|
||||
{
|
||||
'in_bom_for': 100,
|
||||
},
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
self.assertEqual(len(response.data), 4)
|
||||
|
||||
def test_filter_by_related(self):
|
||||
"""Test that we can filter by the 'related' status"""
|
||||
url = reverse('api-part-list')
|
||||
|
Loading…
Reference in New Issue
Block a user