mirror of
https://github.com/inventree/InvenTree.git
synced 2026-08-21 20:45:13 +00:00
On order filter (#12476)
* Add "on order" filter for Part model - Added API filter - Added table filter - Added table column * Bump API version * Add table sorting * Adjust API text
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 528
|
||||
INVENTREE_API_VERSION = 529
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v529 -> 2026-07-26 : https://github.com/inventree/InvenTree/pull/12471
|
||||
- Adds "on_order" filter to the Part API
|
||||
- Enable sorting by "ordering" quantity on the Part API endpoint
|
||||
|
||||
v528 -> 2026-07-26 : https://github.com/inventree/InvenTree/pull/12469
|
||||
- Additional ordering options for SalesOrderAllocation API endpoint
|
||||
|
||||
|
||||
@@ -784,6 +784,15 @@ class PartFilter(FilterSet):
|
||||
return queryset.filter(Q(unallocated_stock__gt=0))
|
||||
return queryset.filter(Q(unallocated_stock__lte=0))
|
||||
|
||||
# on_order filter
|
||||
on_order = rest_filters.BooleanFilter(label='On order', method='filter_on_order')
|
||||
|
||||
def filter_on_order(self, queryset, name, value):
|
||||
"""Filter by whether the Part has any stock on order."""
|
||||
if str2bool(value):
|
||||
return queryset.filter(Q(ordering__gt=0))
|
||||
return queryset.filter(Q(ordering__lte=0))
|
||||
|
||||
convert_from = rest_filters.ModelChoiceFilter(
|
||||
label='Can convert from',
|
||||
queryset=Part.objects.all(),
|
||||
@@ -1096,6 +1105,7 @@ class PartList(
|
||||
'name',
|
||||
'creation_date',
|
||||
'IPN',
|
||||
'ordering',
|
||||
'in_stock',
|
||||
'total_in_stock',
|
||||
'unallocated_stock',
|
||||
|
||||
@@ -2782,6 +2782,25 @@ class PartAPIAggregationTest(InvenTreeAPITestCase):
|
||||
# The annotated quantity must also match the part.on_order quantity
|
||||
self.assertEqual(on_order, p.on_order)
|
||||
|
||||
# Test the 'on_order' filter
|
||||
response = self.get(
|
||||
reverse('api-part-list'),
|
||||
{'category': paint.pk, 'on_order': True},
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
for item in response.data:
|
||||
self.assertGreater(item['ordering'], 0)
|
||||
|
||||
response = self.get(
|
||||
reverse('api-part-list'),
|
||||
{'category': paint.pk, 'on_order': False},
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
for item in response.data:
|
||||
self.assertLessEqual(item['ordering'], 0)
|
||||
|
||||
def test_building(self):
|
||||
"""Test the 'building' quantity annotations."""
|
||||
# Create a new "buildable" part
|
||||
|
||||
Reference in New Issue
Block a user