mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Remove StockExport view (no longer required!)
This commit is contained in:
parent
8bf84ec217
commit
10cc72910d
@ -47,8 +47,6 @@ stock_urls = [
|
||||
|
||||
url(r'^track/', include(stock_tracking_urls)),
|
||||
|
||||
url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
|
||||
|
||||
# Individual stock items
|
||||
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
|
||||
|
||||
|
@ -380,95 +380,6 @@ class StockItemDeleteTestData(AjaxUpdateView):
|
||||
return self.renderJsonResponse(request, form, data)
|
||||
|
||||
|
||||
class StockExport(AjaxView):
|
||||
""" Export stock data from a particular location.
|
||||
Returns a file containing stock information for that location.
|
||||
"""
|
||||
|
||||
model = StockItem
|
||||
role_required = 'stock.view'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
export_format = request.GET.get('format', 'csv').lower()
|
||||
|
||||
# Check if a particular location was specified
|
||||
loc_id = request.GET.get('location', None)
|
||||
location = None
|
||||
|
||||
if loc_id:
|
||||
try:
|
||||
location = StockLocation.objects.get(pk=loc_id)
|
||||
except (ValueError, StockLocation.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Check if a particular supplier was specified
|
||||
sup_id = request.GET.get('supplier', None)
|
||||
supplier = None
|
||||
|
||||
if sup_id:
|
||||
try:
|
||||
supplier = Company.objects.get(pk=sup_id)
|
||||
except (ValueError, Company.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Check if a particular supplier_part was specified
|
||||
sup_part_id = request.GET.get('supplier_part', None)
|
||||
supplier_part = None
|
||||
|
||||
if sup_part_id:
|
||||
try:
|
||||
supplier_part = SupplierPart.objects.get(pk=sup_part_id)
|
||||
except (ValueError, SupplierPart.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Check if a particular part was specified
|
||||
part_id = request.GET.get('part', None)
|
||||
part = None
|
||||
|
||||
if part_id:
|
||||
try:
|
||||
part = Part.objects.get(pk=part_id)
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
||||
if export_format not in GetExportFormats():
|
||||
export_format = 'csv'
|
||||
|
||||
filename = 'InvenTree_Stocktake_{date}.{fmt}'.format(
|
||||
date=datetime.now().strftime("%d-%b-%Y"),
|
||||
fmt=export_format
|
||||
)
|
||||
|
||||
if location:
|
||||
# Check if locations should be cascading
|
||||
cascade = str2bool(request.GET.get('cascade', True))
|
||||
stock_items = location.get_stock_items(cascade)
|
||||
else:
|
||||
stock_items = StockItem.objects.all()
|
||||
|
||||
if part:
|
||||
stock_items = stock_items.filter(part=part)
|
||||
|
||||
if supplier:
|
||||
stock_items = stock_items.filter(supplier_part__supplier=supplier)
|
||||
|
||||
if supplier_part:
|
||||
stock_items = stock_items.filter(supplier_part=supplier_part)
|
||||
|
||||
# Filter out stock items that are not 'in stock'
|
||||
stock_items = stock_items.filter(StockItem.IN_STOCK_FILTER)
|
||||
|
||||
# Pre-fetch related fields to reduce DB queries
|
||||
stock_items = stock_items.prefetch_related('part', 'supplier_part__supplier', 'location', 'purchase_order', 'build')
|
||||
|
||||
dataset = StockItemResource().export(queryset=stock_items)
|
||||
|
||||
filedata = dataset.export(export_format)
|
||||
|
||||
return DownloadFile(filedata, filename)
|
||||
|
||||
|
||||
class StockItemQRCode(QRCodeView):
|
||||
""" View for displaying a QR code for a StockItem object """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user