diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index f45381525e..e02f0d2b99 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -26,20 +26,22 @@ from InvenTree.helpers import DownloadFile, str2bool from InvenTree.mixins import (CreateAPI, ListAPI, ListCreateAPI, RetrieveUpdateAPI, RetrieveUpdateDestroyAPI) from InvenTree.status_codes import PurchaseOrderStatus, SalesOrderStatus -from order.admin import (PurchaseOrderLineItemResource, PurchaseOrderResource, - SalesOrderResource) +from order.admin import (PurchaseOrderExtraLineResource, + PurchaseOrderLineItemResource, PurchaseOrderResource, + SalesOrderExtraLineResource, + SalesOrderLineItemResource, SalesOrderResource) from part.models import Part from plugin.serializers import MetadataSerializer from users.models import Owner -class GeneralExtraLineList: +class GeneralExtraLineList(APIDownloadMixin): """General template for ExtraLine API classes.""" def get_serializer(self, *args, **kwargs): """Return the serializer instance for this endpoint""" try: - params = self.request.query_params + params = self.request.query_params3 kwargs['order_detail'] = str2bool(params.get('order_detail', False)) except AttributeError: @@ -606,6 +608,15 @@ class PurchaseOrderExtraLineList(GeneralExtraLineList, ListCreateAPI): queryset = models.PurchaseOrderExtraLine.objects.all() serializer_class = serializers.PurchaseOrderExtraLineSerializer + def download_queryset(self, queryset, export_format): + """Download this queryset as a file""" + + dataset = PurchaseOrderExtraLineResource().export(queryset=queryset) + filedata = dataset.export(export_format) + filename = f"InvenTree_ExtraPurchaseOrderLines.{export_format}" + + return DownloadFile(filedata, filename) + class PurchaseOrderExtraLineDetail(RetrieveUpdateDestroyAPI): """API endpoint for detail view of a PurchaseOrderExtraLine object.""" @@ -686,6 +697,7 @@ class SalesOrderList(APIDownloadMixin, ListCreateAPI): def download_queryset(self, queryset, export_format): """Download this queryset as a file""" + dataset = SalesOrderResource().export(queryset=queryset) filedata = dataset.export(export_format) @@ -857,7 +869,7 @@ class SalesOrderLineItemFilter(rest_filters.FilterSet): return queryset -class SalesOrderLineItemList(ListCreateAPI): +class SalesOrderLineItemList(APIDownloadMixin, ListCreateAPI): """API endpoint for accessing a list of SalesOrderLineItem objects.""" queryset = models.SalesOrderLineItem.objects.all() @@ -898,6 +910,16 @@ class SalesOrderLineItemList(ListCreateAPI): return queryset + def download_queryset(self, queryset, export_format): + """Download the requested queryset as a file""" + + dataset = SalesOrderLineItemResource().export(queryset=queryset) + filedata = dataset.export(export_format) + + filename = f"InvenTree_SalesOrderItems.{export_format}" + + return DownloadFile(filedata, filename) + filter_backends = [ rest_filters.DjangoFilterBackend, filters.SearchFilter, @@ -924,6 +946,15 @@ class SalesOrderExtraLineList(GeneralExtraLineList, ListCreateAPI): queryset = models.SalesOrderExtraLine.objects.all() serializer_class = serializers.SalesOrderExtraLineSerializer + def download_queryset(self, queryset, export_format): + """Download this queryset as a file""" + + dataset = SalesOrderExtraLineResource().export(queryset=queryset) + filedata = dataset.export(export_format) + filename = f"InvenTree_ExtraSalesOrderLines.{export_format}" + + return DownloadFile(filedata, filename) + class SalesOrderExtraLineDetail(RetrieveUpdateDestroyAPI): """API endpoint for detail view of a SalesOrderExtraLine object.""" diff --git a/InvenTree/order/templates/order/sales_order_detail.html b/InvenTree/order/templates/order/sales_order_detail.html index a3c25391f9..5b28b88f1a 100644 --- a/InvenTree/order/templates/order/sales_order_detail.html +++ b/InvenTree/order/templates/order/sales_order_detail.html @@ -31,8 +31,6 @@