Adds ability to download purchase order line item table

This commit is contained in:
Oliver 2022-03-04 00:45:30 +11:00
parent f6b574a127
commit 846899fa53
2 changed files with 33 additions and 4 deletions

View File

@ -16,10 +16,11 @@ from rest_framework.response import Response
from company.models import SupplierPart
from InvenTree.filters import InvenTreeOrderingFilter
from InvenTree.helpers import str2bool
from InvenTree.helpers import str2bool, DownloadFile
from InvenTree.api import AttachmentMixin
from InvenTree.status_codes import PurchaseOrderStatus, SalesOrderStatus
from order.admin import POLineItemResource
import order.models as models
import order.serializers as serializers
from part.models import Part
@ -370,6 +371,34 @@ class POLineItemList(generics.ListCreateAPIView):
return queryset
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
# Check if we wish to export the queried data to a file
export_format = request.query_params.get('export', None)
if export_format:
export_format = str(export_format).strip().lower()
if export_format in ['csv', 'tsv', 'xls', 'xlsx']:
dataset = POLineItemResource().export(queryset=queryset)
filedata = dataset.export(export_format)
filename = f"InvenTree_PurchaseOrderData.{export_format}"
return DownloadFile(filedata, filename)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
filter_backends = [
rest_filters.DjangoFilterBackend,
filters.SearchFilter,

View File

@ -1051,7 +1051,7 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
var target = options.filter_target || '#filter-list-purchase-order-lines';
setupFilterList('purchaseorderlineitem', $(table), target);
setupFilterList('purchaseorderlineitem', $(table), target, {download: true});
function setupCallbacks() {
if (options.allow_edit) {
@ -1078,7 +1078,7 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
});
}
});
})
});
// Callback for "edit" button
$(table).find('.button-line-edit').click(function() {
@ -2583,7 +2583,7 @@ function loadSalesOrderLineItemTable(table, options={}) {
fields: fields,
data: data,
title: '{% trans "Duplicate Line Item" %}',
onSuccess: function(response) {
onSuccess: function(response) {
$(table).bootstrapTable('refresh');
}
});