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:
Oliver 2022-06-29 11:47:17 +10:00 committed by GitHub
parent 26d5d15b49
commit 825e4b4cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -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()

View File

@ -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')