2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-10-14 21:22:20 +00:00

refactor(backend): fix remaining undocumented path based serializer mutations (#10495)

* fix remaining undocumented path based serializer mutations
closes #9481

* bump api_version

* fix indention

* add description for filter

* fix missing OutputOptions

* fix default description lookup
This commit is contained in:
Matthias Mair
2025-10-06 02:21:36 +02:00
committed by GitHub
parent d7b4997da2
commit 946418e175
5 changed files with 49 additions and 14 deletions

View File

@@ -1,12 +1,17 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 401
INVENTREE_API_VERSION = 402
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v402 -> 2025-10-05 : https://github.com/inventree/InvenTree/pull/10495
- Refactors 'part_detail' param in BuildList API endpoint
- Refactors 'order_detail' param in GeneralExtraLineList API endpoint
- Refactors 'part_detail', 'template_detail' param in PartParameterList / PartParameterDetail API endpoint
v401 -> 2025-10-04 : https://github.com/inventree/InvenTree/pull/10381
- Adds machine properties to machine API endpoints

View File

@@ -218,7 +218,7 @@ class InvenTreeOutputOption:
"""Represents an available output option with description, flag name, and default value."""
DEFAULT_DESCRIPTIONS = {
'part_detail': 'Include detailed information about the related part in the response',
'part_detail': 'Include detailed information about the related part in the response',
'item_detail': 'Include detailed information about the item in the response',
'order_detail': 'Include detailed information about the sales order in the response',
'location_detail': 'Include detailed information about the stock location in the response',
@@ -231,7 +231,7 @@ class InvenTreeOutputOption:
self.flag = flag
self.default = default
if description is None:
if description is None or description == '':
self.description = self.DEFAULT_DESCRIPTIONS.get(flag, '')
else:
self.description = description

View File

@@ -332,17 +332,22 @@ class BuildMixin:
return queryset
class BuildList(DataExportViewMixin, BuildMixin, ListCreateAPI):
class BuildListOutputOptions(OutputConfiguration):
"""Output options for the BuildList endpoint."""
OPTIONS = [InvenTreeOutputOption('part_detail', default=True)]
class BuildList(DataExportViewMixin, BuildMixin, OutputOptionsMixin, ListCreateAPI):
"""API endpoint for accessing a list of Build objects.
- GET: Return list of objects (with filters)
- POST: Create a new Build object
"""
output_options = BuildListOutputOptions
filterset_class = BuildFilter
filter_backends = SEARCH_ORDER_FILTER_ALIAS
ordering_fields = [
'reference',
'part__name',
@@ -360,14 +365,11 @@ class BuildList(DataExportViewMixin, BuildMixin, ListCreateAPI):
'level',
'external',
]
ordering_field_aliases = {
'reference': ['reference_int', 'reference'],
'project_code': ['project_code__code'],
}
ordering = '-reference'
search_fields = [
'reference',
'title',

View File

@@ -58,6 +58,12 @@ from part.models import Part
from users.models import Owner
class GeneralExtraLineListOutputOptions(OutputConfiguration):
"""Output options for the GeneralExtraLineList endpoint."""
OPTIONS = [InvenTreeOutputOption('order_detail')]
class GeneralExtraLineList(SerializerContextMixin, DataExportViewMixin):
"""General template for ExtraLine API classes."""
@@ -69,6 +75,8 @@ class GeneralExtraLineList(SerializerContextMixin, DataExportViewMixin):
return queryset
output_options = GeneralExtraLineListOutputOptions
filter_backends = SEARCH_ORDER_FILTER
ordering_fields = ['quantity', 'notes', 'reference']
@@ -733,7 +741,9 @@ class PurchaseOrderLineItemDetail(
output_options = PurchaseOrderLineItemOutputOptions
class PurchaseOrderExtraLineList(GeneralExtraLineList, ListCreateAPI):
class PurchaseOrderExtraLineList(
GeneralExtraLineList, OutputOptionsMixin, ListCreateAPI
):
"""API endpoint for accessing a list of PurchaseOrderExtraLine objects."""
queryset = models.PurchaseOrderExtraLine.objects.all()
@@ -1070,7 +1080,7 @@ class SalesOrderLineItemDetail(
output_options = SalesOrderLineItemOutputOptions
class SalesOrderExtraLineList(GeneralExtraLineList, ListCreateAPI):
class SalesOrderExtraLineList(GeneralExtraLineList, OutputOptionsMixin, ListCreateAPI):
"""API endpoint for accessing a list of SalesOrderExtraLine objects."""
queryset = models.SalesOrderExtraLine.objects.all()
@@ -1660,7 +1670,7 @@ class ReturnOrderLineItemDetail(
output_options = ReturnOrderLineItemOutputOptions
class ReturnOrderExtraLineList(GeneralExtraLineList, ListCreateAPI):
class ReturnOrderExtraLineList(GeneralExtraLineList, OutputOptionsMixin, ListCreateAPI):
"""API endpoint for accessing a list of ReturnOrderExtraLine objects."""
queryset = models.ReturnOrderExtraLine.objects.all()

View File

@@ -1365,11 +1365,25 @@ class PartParameterTemplateDetail(PartParameterTemplateMixin, RetrieveUpdateDest
"""API endpoint for accessing the detail view for a PartParameterTemplate object."""
class PartParameterOutputOptions(OutputConfiguration):
"""Output options for the PartParameter endpoints."""
OPTIONS = [
InvenTreeOutputOption('part_detail'),
InvenTreeOutputOption(
'template_detail',
default=True,
description='Include detailed information about the part parameter template.',
),
]
class PartParameterAPIMixin:
"""Mixin class for PartParameter API endpoints."""
queryset = PartParameter.objects.all()
serializer_class = part_serializers.PartParameterSerializer
output_options = PartParameterOutputOptions
def get_queryset(self, *args, **kwargs):
"""Override get_queryset method to prefetch related fields."""
@@ -1414,7 +1428,9 @@ class PartParameterFilter(FilterSet):
return queryset.filter(part=part)
class PartParameterList(PartParameterAPIMixin, DataExportViewMixin, ListCreateAPI):
class PartParameterList(
PartParameterAPIMixin, OutputOptionsMixin, DataExportViewMixin, ListCreateAPI
):
"""API endpoint for accessing a list of PartParameter objects.
- GET: Return list of PartParameter objects
@@ -1442,7 +1458,9 @@ class PartParameterList(PartParameterAPIMixin, DataExportViewMixin, ListCreateAP
]
class PartParameterDetail(PartParameterAPIMixin, RetrieveUpdateDestroyAPI):
class PartParameterDetail(
PartParameterAPIMixin, OutputOptionsMixin, RetrieveUpdateDestroyAPI
):
"""API endpoint for detail view of a single PartParameter object."""