Export stock based on supplier

This commit is contained in:
Oliver Walters 2019-09-08 23:53:09 +10:00
parent 3d5542181a
commit 231a669fe5
3 changed files with 69 additions and 25 deletions

View File

@ -27,4 +27,18 @@
] ]
}); });
$("#stock-export").click(function() {
launchModalForm("{% url 'stock-export-options' %}", {
submit_text: "Export",
success: function(response) {
var url = "{% url 'stock-export' %}";
url += "?format=" + response.format;
url += "&supplier={{ company.id }}";
location.href = url;
},
});
});
{% endblock %} {% endblock %}

View File

@ -68,8 +68,7 @@
}); });
$("#stock-export").click(function() { $("#stock-export").click(function() {
launchModalForm("{% url 'stock-export-options' %}", launchModalForm("{% url 'stock-export-options' %}", {
{
submit_text: "Export", submit_text: "Export",
success: function(response) { success: function(response) {
var url = "{% url 'stock-export' %}"; var url = "{% url 'stock-export' %}";
@ -83,8 +82,7 @@
location.href = url; location.href = url;
} }
} });
);
}); });
$('#location-create').click(function () { $('#location-create').click(function () {

View File

@ -24,6 +24,7 @@ from datetime import datetime
import tablib import tablib
from company.models import Company
from part.models import Part from part.models import Part
from .models import StockItem, StockLocation, StockItemTracking from .models import StockItem, StockLocation, StockItemTracking
@ -164,33 +165,59 @@ class StockExport(AjaxView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
export_format = request.GET.get('format', 'csv').lower() export_format = request.GET.get('format', 'csv').lower()
cascade = str2bool(request.GET.get('cascade', True))
location = None # Check if a particular location was specified
loc_id = request.GET.get('location', None) loc_id = request.GET.get('location', None)
path = 'All-Locations' location = None
if loc_id: if loc_id:
try: try:
location = StockLocation.objects.get(pk=loc_id) location = StockLocation.objects.get(pk=loc_id)
path = location.pathstring.replace('/', ':')
except (ValueError, StockLocation.DoesNotExist): except (ValueError, StockLocation.DoesNotExist):
location = None 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 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(): if export_format not in GetExportFormats():
export_format = 'csv' export_format = 'csv'
filename = 'InvenTree_Stocktake_{loc}_{date}.{fmt}'.format( filename = 'InvenTree_Stocktake_{date}.{fmt}'.format(
loc=path,
date=datetime.now().strftime("%d-%b-%Y"), date=datetime.now().strftime("%d-%b-%Y"),
fmt=export_format fmt=export_format
) )
if location: if location:
# CHeck if locations should be cascading
cascade = str2bool(request.GET.get('cascade', True))
stock_items = location.get_stock_items(cascade) stock_items = location.get_stock_items(cascade)
else: else:
cascade = True cascade = True
stock_items = StockItem.objects.all() 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)
# Filter out stock items that are not 'in stock' # Filter out stock items that are not 'in stock'
stock_items = stock_items.filter(customer=None) stock_items = stock_items.filter(customer=None)
stock_items = stock_items.filter(belongs_to=None) stock_items = stock_items.filter(belongs_to=None)
@ -235,8 +262,13 @@ class StockExport(AjaxView):
line.append('') line.append('')
line.append('') line.append('')
if item.location:
line.append(item.location.pk) line.append(item.location.pk)
line.append(item.location.name) line.append(item.location.name)
else:
line.append('')
line.append('')
line.append(item.quantity) line.append(item.quantity)
line.append(item.batch) line.append(item.batch)
line.append(item.serial) line.append(item.serial)