diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index 94f6354fa1..c83990d960 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -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 diff --git a/src/backend/InvenTree/InvenTree/fields.py b/src/backend/InvenTree/InvenTree/fields.py index ea2dd7fe28..c1495488f7 100644 --- a/src/backend/InvenTree/InvenTree/fields.py +++ b/src/backend/InvenTree/InvenTree/fields.py @@ -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 diff --git a/src/backend/InvenTree/build/api.py b/src/backend/InvenTree/build/api.py index a1448afac7..b7dfac9904 100644 --- a/src/backend/InvenTree/build/api.py +++ b/src/backend/InvenTree/build/api.py @@ -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', diff --git a/src/backend/InvenTree/order/api.py b/src/backend/InvenTree/order/api.py index b1dbbbfbfc..470550e6eb 100644 --- a/src/backend/InvenTree/order/api.py +++ b/src/backend/InvenTree/order/api.py @@ -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() diff --git a/src/backend/InvenTree/part/api.py b/src/backend/InvenTree/part/api.py index 56bed73f85..0f357c1370 100644 --- a/src/backend/InvenTree/part/api.py +++ b/src/backend/InvenTree/part/api.py @@ -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."""