mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds view for exporting sales order
This commit is contained in:
parent
0bc1715601
commit
996ccbe5bd
@ -77,6 +77,14 @@ class POLineItemResource(ModelResource):
|
|||||||
class SOLineItemResource(ModelResource):
|
class SOLineItemResource(ModelResource):
|
||||||
""" Class for managing import / export of SOLineItem data """
|
""" Class for managing import / export of SOLineItem data """
|
||||||
|
|
||||||
|
part_name = Field(attribute='part__name', readonly=True)
|
||||||
|
|
||||||
|
IPN = Field(attribute='part__IPN', readonly=True)
|
||||||
|
|
||||||
|
description = Field(attribute='part__description', readonly=True)
|
||||||
|
|
||||||
|
fulfilled = Field(attribute='fulfilled_quantity', readonly=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SalesOrderLineItem
|
model = SalesOrderLineItem
|
||||||
skip_unchanged = True
|
skip_unchanged = True
|
||||||
|
@ -36,6 +36,7 @@ purchase_order_urls = [
|
|||||||
sales_order_detail_urls = [
|
sales_order_detail_urls = [
|
||||||
url(r'^cancel/', views.SalesOrderCancel.as_view(), name='so-cancel'),
|
url(r'^cancel/', views.SalesOrderCancel.as_view(), name='so-cancel'),
|
||||||
url(r'^ship/', views.SalesOrderShip.as_view(), name='so-ship'),
|
url(r'^ship/', views.SalesOrderShip.as_view(), name='so-ship'),
|
||||||
|
url(r'^export/', views.SalesOrderExport.as_view(), name='so-export'),
|
||||||
|
|
||||||
url(r'^.*$', views.SalesOrderDetail.as_view(), name='so-detail'),
|
url(r'^.*$', views.SalesOrderDetail.as_view(), name='so-detail'),
|
||||||
]
|
]
|
||||||
|
@ -23,7 +23,7 @@ from decimal import Decimal, InvalidOperation
|
|||||||
from .models import PurchaseOrder, PurchaseOrderLineItem
|
from .models import PurchaseOrder, PurchaseOrderLineItem
|
||||||
from .models import SalesOrder, SalesOrderLineItem
|
from .models import SalesOrder, SalesOrderLineItem
|
||||||
from .models import SalesOrderAllocation
|
from .models import SalesOrderAllocation
|
||||||
from .admin import POLineItemResource
|
from .admin import POLineItemResource, SOLineItemResource
|
||||||
from build.models import Build
|
from build.models import Build
|
||||||
from company.models import Company, SupplierPart # ManufacturerPart
|
from company.models import Company, SupplierPart # ManufacturerPart
|
||||||
from stock.models import StockItem
|
from stock.models import StockItem
|
||||||
@ -436,6 +436,33 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
return HttpResponseRedirect(reverse('po-detail', kwargs={'pk': self.kwargs['pk']}))
|
return HttpResponseRedirect(reverse('po-detail', kwargs={'pk': self.kwargs['pk']}))
|
||||||
|
|
||||||
|
|
||||||
|
class SalesOrderExport(AjaxView):
|
||||||
|
"""
|
||||||
|
Export a sales order
|
||||||
|
|
||||||
|
- File format can optionally be passed as a query parameter e.g. ?format=CSV
|
||||||
|
- Default file format is CSV
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = SalesOrder
|
||||||
|
|
||||||
|
role_required = 'sales_order.view'
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
order = get_object_or_404(SalesOrder, pk=self.kwargs.get('pk', None))
|
||||||
|
|
||||||
|
export_format = request.GET.get('format', 'csv')
|
||||||
|
|
||||||
|
filename = f"{str(order)} - {order.customer.name}.{export_format}"
|
||||||
|
|
||||||
|
dataset = SOLineItemResource().export(queryset=order.lines.all())
|
||||||
|
|
||||||
|
filedata = dataset.export(format=export_format)
|
||||||
|
|
||||||
|
return DownloadFile(filedata, filename)
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderExport(AjaxView):
|
class PurchaseOrderExport(AjaxView):
|
||||||
""" File download for a purchase order
|
""" File download for a purchase order
|
||||||
|
|
||||||
@ -450,7 +477,7 @@ class PurchaseOrderExport(AjaxView):
|
|||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
order = get_object_or_404(PurchaseOrder, pk=self.kwargs['pk'])
|
order = get_object_or_404(PurchaseOrder, pk=self.kwargs.get('pk', None))
|
||||||
|
|
||||||
export_format = request.GET.get('format', 'csv')
|
export_format = request.GET.get('format', 'csv')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user