2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

Build category filter (#8940)

* Add 'category' filter to BuildList

- Allows filtering by part category

* Add filter element to build table

* Bump API version
This commit is contained in:
Oliver
2025-01-22 22:22:03 +11:00
committed by GitHub
parent 19d7825fa6
commit e9bc4645ca
4 changed files with 61 additions and 17 deletions

View File

@ -1,36 +1,39 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 303
INVENTREE_API_VERSION = 304
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v303 - 2025-01-20 - https://github.com/inventree/InvenTree/pull/8915
v304 - 2025-01-22 : https://github.com/inventree/InvenTree/pull/8940
- Adds "category" filter to build list API
v303 - 2025-01-20 : https://github.com/inventree/InvenTree/pull/8915
- Adds "start_date" field to Build model and API endpoints
- Adds additional API filtering and sorting options for Build list
v302 - 2025-01-18 - https://github.com/inventree/InvenTree/pull/8905
v302 - 2025-01-18 : https://github.com/inventree/InvenTree/pull/8905
- Fix schema definition on the /label/print endpoint
v301 - 2025-01-14 - https://github.com/inventree/InvenTree/pull/8894
v301 - 2025-01-14 : https://github.com/inventree/InvenTree/pull/8894
- Remove ui preferences from the API
v300 - 2025-01-13 - https://github.com/inventree/InvenTree/pull/8886
v300 - 2025-01-13 : https://github.com/inventree/InvenTree/pull/8886
- Allow null value for 'expiry_date' field introduced in #8867
v299 - 2025-01-10 - https://github.com/inventree/InvenTree/pull/8867
v299 - 2025-01-10 : https://github.com/inventree/InvenTree/pull/8867
- Adds 'expiry_date' field to the PurchaseOrderReceive API endpoint
- Adds 'default_expiry` field to the PartBriefSerializer, affecting API endpoints which use it
v298 - 2025-01-07 - https://github.com/inventree/InvenTree/pull/8848
v298 - 2025-01-07 : https://github.com/inventree/InvenTree/pull/8848
- Adds 'created_by' field to PurchaseOrder API endpoints
- Adds 'created_by' field to SalesOrder API endpoints
- Adds 'created_by' field to ReturnOrder API endpoints
v297 - 2024-12-29 - https://github.com/inventree/InvenTree/pull/8438
v297 - 2024-12-29 : https://github.com/inventree/InvenTree/pull/8438
- Adjustments to the CustomUserState API endpoints and serializers
v296 - 2024-12-25 : https://github.com/inventree/InvenTree/pull/8732

View File

@ -13,7 +13,7 @@ from rest_framework.exceptions import ValidationError
import build.admin
import build.serializers
import common.models
import part.models
import part.models as part_models
from build.models import Build, BuildItem, BuildLine
from build.status_codes import BuildStatus, BuildStatusGroups
from generic.states.api import StatusView
@ -77,7 +77,10 @@ class BuildFilter(rest_filters.FilterSet):
return queryset
part = rest_filters.ModelChoiceFilter(
queryset=part.models.Part.objects.all(), field_name='part', method='filter_part'
queryset=part_models.Part.objects.all(),
field_name='part',
method='filter_part',
label=_('Part'),
)
def filter_part(self, queryset, name, part):
@ -94,6 +97,17 @@ class BuildFilter(rest_filters.FilterSet):
else:
return queryset.filter(part=part)
category = rest_filters.ModelChoiceFilter(
queryset=part_models.PartCategory.objects.all(),
method='filter_category',
label=_('Category'),
)
def filter_category(self, queryset, name, category):
"""Filter by part category (including sub-categories)."""
categories = category.get_descendants(include_self=True)
return queryset.filter(part__category__in=categories)
ancestor = rest_filters.ModelChoiceFilter(
queryset=Build.objects.all(),
label=_('Ancestor Build'),
@ -417,7 +431,7 @@ class BuildLineFilter(rest_filters.FilterSet):
)
part = rest_filters.ModelChoiceFilter(
queryset=part.models.Part.objects.all(),
queryset=part_models.Part.objects.all(),
label=_('Part'),
field_name='bom_item__sub_part',
)
@ -729,7 +743,7 @@ class BuildItemFilter(rest_filters.FilterSet):
return queryset
part = rest_filters.ModelChoiceFilter(
queryset=part.models.Part.objects.all(),
queryset=part_models.Part.objects.all(),
label=_('Part'),
method='filter_part',
field_name='stock_item__part',