mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-15 05:32:21 +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:
@@ -1,12 +1,17 @@
|
|||||||
"""InvenTree API version information."""
|
"""InvenTree API version information."""
|
||||||
|
|
||||||
# InvenTree API version
|
# 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."""
|
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||||
|
|
||||||
INVENTREE_API_TEXT = """
|
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
|
v401 -> 2025-10-04 : https://github.com/inventree/InvenTree/pull/10381
|
||||||
- Adds machine properties to machine API endpoints
|
- Adds machine properties to machine API endpoints
|
||||||
|
|
||||||
|
@@ -218,7 +218,7 @@ class InvenTreeOutputOption:
|
|||||||
"""Represents an available output option with description, flag name, and default value."""
|
"""Represents an available output option with description, flag name, and default value."""
|
||||||
|
|
||||||
DEFAULT_DESCRIPTIONS = {
|
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',
|
'item_detail': 'Include detailed information about the item in the response',
|
||||||
'order_detail': 'Include detailed information about the sales order 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',
|
'location_detail': 'Include detailed information about the stock location in the response',
|
||||||
@@ -231,7 +231,7 @@ class InvenTreeOutputOption:
|
|||||||
self.flag = flag
|
self.flag = flag
|
||||||
self.default = default
|
self.default = default
|
||||||
|
|
||||||
if description is None:
|
if description is None or description == '':
|
||||||
self.description = self.DEFAULT_DESCRIPTIONS.get(flag, '')
|
self.description = self.DEFAULT_DESCRIPTIONS.get(flag, '')
|
||||||
else:
|
else:
|
||||||
self.description = description
|
self.description = description
|
||||||
|
@@ -332,17 +332,22 @@ class BuildMixin:
|
|||||||
return queryset
|
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.
|
"""API endpoint for accessing a list of Build objects.
|
||||||
|
|
||||||
- GET: Return list of objects (with filters)
|
- GET: Return list of objects (with filters)
|
||||||
- POST: Create a new Build object
|
- POST: Create a new Build object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
output_options = BuildListOutputOptions
|
||||||
filterset_class = BuildFilter
|
filterset_class = BuildFilter
|
||||||
|
|
||||||
filter_backends = SEARCH_ORDER_FILTER_ALIAS
|
filter_backends = SEARCH_ORDER_FILTER_ALIAS
|
||||||
|
|
||||||
ordering_fields = [
|
ordering_fields = [
|
||||||
'reference',
|
'reference',
|
||||||
'part__name',
|
'part__name',
|
||||||
@@ -360,14 +365,11 @@ class BuildList(DataExportViewMixin, BuildMixin, ListCreateAPI):
|
|||||||
'level',
|
'level',
|
||||||
'external',
|
'external',
|
||||||
]
|
]
|
||||||
|
|
||||||
ordering_field_aliases = {
|
ordering_field_aliases = {
|
||||||
'reference': ['reference_int', 'reference'],
|
'reference': ['reference_int', 'reference'],
|
||||||
'project_code': ['project_code__code'],
|
'project_code': ['project_code__code'],
|
||||||
}
|
}
|
||||||
|
|
||||||
ordering = '-reference'
|
ordering = '-reference'
|
||||||
|
|
||||||
search_fields = [
|
search_fields = [
|
||||||
'reference',
|
'reference',
|
||||||
'title',
|
'title',
|
||||||
|
@@ -58,6 +58,12 @@ from part.models import Part
|
|||||||
from users.models import Owner
|
from users.models import Owner
|
||||||
|
|
||||||
|
|
||||||
|
class GeneralExtraLineListOutputOptions(OutputConfiguration):
|
||||||
|
"""Output options for the GeneralExtraLineList endpoint."""
|
||||||
|
|
||||||
|
OPTIONS = [InvenTreeOutputOption('order_detail')]
|
||||||
|
|
||||||
|
|
||||||
class GeneralExtraLineList(SerializerContextMixin, DataExportViewMixin):
|
class GeneralExtraLineList(SerializerContextMixin, DataExportViewMixin):
|
||||||
"""General template for ExtraLine API classes."""
|
"""General template for ExtraLine API classes."""
|
||||||
|
|
||||||
@@ -69,6 +75,8 @@ class GeneralExtraLineList(SerializerContextMixin, DataExportViewMixin):
|
|||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
output_options = GeneralExtraLineListOutputOptions
|
||||||
|
|
||||||
filter_backends = SEARCH_ORDER_FILTER
|
filter_backends = SEARCH_ORDER_FILTER
|
||||||
|
|
||||||
ordering_fields = ['quantity', 'notes', 'reference']
|
ordering_fields = ['quantity', 'notes', 'reference']
|
||||||
@@ -733,7 +741,9 @@ class PurchaseOrderLineItemDetail(
|
|||||||
output_options = PurchaseOrderLineItemOutputOptions
|
output_options = PurchaseOrderLineItemOutputOptions
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderExtraLineList(GeneralExtraLineList, ListCreateAPI):
|
class PurchaseOrderExtraLineList(
|
||||||
|
GeneralExtraLineList, OutputOptionsMixin, ListCreateAPI
|
||||||
|
):
|
||||||
"""API endpoint for accessing a list of PurchaseOrderExtraLine objects."""
|
"""API endpoint for accessing a list of PurchaseOrderExtraLine objects."""
|
||||||
|
|
||||||
queryset = models.PurchaseOrderExtraLine.objects.all()
|
queryset = models.PurchaseOrderExtraLine.objects.all()
|
||||||
@@ -1070,7 +1080,7 @@ class SalesOrderLineItemDetail(
|
|||||||
output_options = SalesOrderLineItemOutputOptions
|
output_options = SalesOrderLineItemOutputOptions
|
||||||
|
|
||||||
|
|
||||||
class SalesOrderExtraLineList(GeneralExtraLineList, ListCreateAPI):
|
class SalesOrderExtraLineList(GeneralExtraLineList, OutputOptionsMixin, ListCreateAPI):
|
||||||
"""API endpoint for accessing a list of SalesOrderExtraLine objects."""
|
"""API endpoint for accessing a list of SalesOrderExtraLine objects."""
|
||||||
|
|
||||||
queryset = models.SalesOrderExtraLine.objects.all()
|
queryset = models.SalesOrderExtraLine.objects.all()
|
||||||
@@ -1660,7 +1670,7 @@ class ReturnOrderLineItemDetail(
|
|||||||
output_options = ReturnOrderLineItemOutputOptions
|
output_options = ReturnOrderLineItemOutputOptions
|
||||||
|
|
||||||
|
|
||||||
class ReturnOrderExtraLineList(GeneralExtraLineList, ListCreateAPI):
|
class ReturnOrderExtraLineList(GeneralExtraLineList, OutputOptionsMixin, ListCreateAPI):
|
||||||
"""API endpoint for accessing a list of ReturnOrderExtraLine objects."""
|
"""API endpoint for accessing a list of ReturnOrderExtraLine objects."""
|
||||||
|
|
||||||
queryset = models.ReturnOrderExtraLine.objects.all()
|
queryset = models.ReturnOrderExtraLine.objects.all()
|
||||||
|
@@ -1365,11 +1365,25 @@ class PartParameterTemplateDetail(PartParameterTemplateMixin, RetrieveUpdateDest
|
|||||||
"""API endpoint for accessing the detail view for a PartParameterTemplate object."""
|
"""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:
|
class PartParameterAPIMixin:
|
||||||
"""Mixin class for PartParameter API endpoints."""
|
"""Mixin class for PartParameter API endpoints."""
|
||||||
|
|
||||||
queryset = PartParameter.objects.all()
|
queryset = PartParameter.objects.all()
|
||||||
serializer_class = part_serializers.PartParameterSerializer
|
serializer_class = part_serializers.PartParameterSerializer
|
||||||
|
output_options = PartParameterOutputOptions
|
||||||
|
|
||||||
def get_queryset(self, *args, **kwargs):
|
def get_queryset(self, *args, **kwargs):
|
||||||
"""Override get_queryset method to prefetch related fields."""
|
"""Override get_queryset method to prefetch related fields."""
|
||||||
@@ -1414,7 +1428,9 @@ class PartParameterFilter(FilterSet):
|
|||||||
return queryset.filter(part=part)
|
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.
|
"""API endpoint for accessing a list of PartParameter objects.
|
||||||
|
|
||||||
- GET: Return 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."""
|
"""API endpoint for detail view of a single PartParameter object."""
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user