mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds exporter and download button for sales orders
This commit is contained in:
parent
1b1f7634b7
commit
d0ddb47b1f
@ -135,6 +135,23 @@ class PurchaseOrderExtraLineResource(ModelResource):
|
||||
model = PurchaseOrderExtraLine
|
||||
|
||||
|
||||
class SalesOrderResource(ModelResource):
|
||||
"""
|
||||
Class for managing import / export of SalesOrder data
|
||||
"""
|
||||
|
||||
# Add number of line items
|
||||
line_items = Field(attribute='line_count', widget=widgets.IntegerWidget(), readonly=True)
|
||||
|
||||
# Is this order overdue?
|
||||
overdue = Field(attribute='is_overdue', widget=widgets.BooleanWidget(), readonly=True)
|
||||
|
||||
class Meta:
|
||||
model = SalesOrder
|
||||
skip_unchanged = True
|
||||
clean_model_instances = True
|
||||
|
||||
|
||||
class SalesOrderLineItemResource(ModelResource):
|
||||
"""
|
||||
Class for managing import / export of SalesOrderLineItem data
|
||||
|
@ -21,6 +21,7 @@ from InvenTree.api import AttachmentMixin, APIDownloadMixin
|
||||
from InvenTree.status_codes import PurchaseOrderStatus, SalesOrderStatus
|
||||
|
||||
from order.admin import PurchaseOrderResource, PurchaseOrderLineItemResource
|
||||
from order.admin import SalesOrderResource
|
||||
import order.models as models
|
||||
import order.serializers as serializers
|
||||
from part.models import Part
|
||||
@ -583,7 +584,7 @@ class SalesOrderAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, Attachme
|
||||
serializer_class = serializers.SalesOrderAttachmentSerializer
|
||||
|
||||
|
||||
class SalesOrderList(generics.ListCreateAPIView):
|
||||
class SalesOrderList(APIDownloadMixin, generics.ListCreateAPIView):
|
||||
"""
|
||||
API endpoint for accessing a list of SalesOrder objects.
|
||||
|
||||
@ -633,6 +634,15 @@ class SalesOrderList(generics.ListCreateAPIView):
|
||||
|
||||
return queryset
|
||||
|
||||
def download_queryset(self, queryset, export_format):
|
||||
dataset = SalesOrderResource().export(queryset=queryset)
|
||||
|
||||
filedata = dataset.export(export_format)
|
||||
|
||||
filename = f"InvenTree_SalesOrders.{export_format}"
|
||||
|
||||
return DownloadFile(filedata, filename)
|
||||
|
||||
def filter_queryset(self, queryset):
|
||||
"""
|
||||
Perform custom filtering operations on the SalesOrder queryset.
|
||||
|
@ -2093,7 +2093,9 @@ function loadSalesOrderTable(table, options) {
|
||||
|
||||
options.url = options.url || '{% url "api-so-list" %}';
|
||||
|
||||
setupFilterList('salesorder', $(table));
|
||||
var target = '#filter-list-salesorder';
|
||||
|
||||
setupFilterList('salesorder', $(table), target, {download: true});
|
||||
|
||||
$(table).inventreeTable({
|
||||
url: options.url,
|
||||
|
Loading…
Reference in New Issue
Block a user