mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1843 from SchrodingersGat/stock-export
Stock export
This commit is contained in:
commit
af68ea23c3
@ -267,16 +267,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#stock-export").click(function() {
|
$("#stock-export").click(function() {
|
||||||
launchModalForm("{% url 'stock-export-options' %}", {
|
exportStock({
|
||||||
submit_text: '{% trans "Export" %}',
|
supplier: {{ company.id }}
|
||||||
success: function(response) {
|
|
||||||
var url = "{% url 'stock-export' %}";
|
|
||||||
|
|
||||||
url += "?format=" + response.format;
|
|
||||||
url += "&supplier={{ company.id }}";
|
|
||||||
|
|
||||||
location.href = url;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -284,18 +284,11 @@ loadStockTable($("#stock-table"), {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#stock-export").click(function() {
|
$("#stock-export").click(function() {
|
||||||
launchModalForm("{% url 'stock-export-options' %}", {
|
|
||||||
submit_text: '{% trans "Export" %}',
|
|
||||||
success: function(response) {
|
|
||||||
var url = "{% url 'stock-export' %}";
|
|
||||||
|
|
||||||
url += "?format=" + response.format;
|
exportStock({
|
||||||
url += "&cascade=" + response.cascade;
|
supplier_part: {{ part.pk }},
|
||||||
url += "&supplier_part={{ part.id }}";
|
|
||||||
|
|
||||||
location.href = url;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#item-create").click(function() {
|
$("#item-create").click(function() {
|
||||||
|
@ -644,17 +644,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#stock-export").click(function() {
|
$("#stock-export").click(function() {
|
||||||
launchModalForm("{% url 'stock-export-options' %}", {
|
|
||||||
submit_text: "{% trans 'Export' %}",
|
|
||||||
success: function(response) {
|
|
||||||
var url = "{% url 'stock-export' %}";
|
|
||||||
|
|
||||||
url += "?format=" + response.format;
|
exportStock({
|
||||||
url += "&cascade=" + response.cascade;
|
part: {{ part.pk }}
|
||||||
url += "&part={{ part.id }}";
|
|
||||||
|
|
||||||
location.href = url;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ from django.core.exceptions import ValidationError
|
|||||||
|
|
||||||
from mptt.fields import TreeNodeChoiceField
|
from mptt.fields import TreeNodeChoiceField
|
||||||
|
|
||||||
from InvenTree.helpers import GetExportFormats
|
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
from InvenTree.fields import RoundingDecimalFormField
|
from InvenTree.fields import RoundingDecimalFormField
|
||||||
from InvenTree.fields import DatePickerFormField
|
from InvenTree.fields import DatePickerFormField
|
||||||
@ -226,33 +225,6 @@ class TestReportFormatForm(HelperForm):
|
|||||||
template = forms.ChoiceField(label=_('Template'), help_text=_('Select test report template'))
|
template = forms.ChoiceField(label=_('Template'), help_text=_('Select test report template'))
|
||||||
|
|
||||||
|
|
||||||
class ExportOptionsForm(HelperForm):
|
|
||||||
""" Form for selecting stock export options """
|
|
||||||
|
|
||||||
file_format = forms.ChoiceField(label=_('File Format'), help_text=_('Select output file format'))
|
|
||||||
|
|
||||||
include_sublocations = forms.BooleanField(required=False, initial=True, label=_('Include sublocations'), help_text=_("Include stock items in sub locations"))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = StockLocation
|
|
||||||
fields = [
|
|
||||||
'file_format',
|
|
||||||
'include_sublocations',
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_format_choices(self):
|
|
||||||
""" File format choices """
|
|
||||||
|
|
||||||
choices = [(x, x.upper()) for x in GetExportFormats()]
|
|
||||||
|
|
||||||
return choices
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
self.fields['file_format'].choices = self.get_format_choices()
|
|
||||||
|
|
||||||
|
|
||||||
class InstallStockForm(HelperForm):
|
class InstallStockForm(HelperForm):
|
||||||
"""
|
"""
|
||||||
Form for manually installing a stock item into another stock item
|
Form for manually installing a stock item into another stock item
|
||||||
|
@ -227,20 +227,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
$("#stock-export").click(function() {
|
$("#stock-export").click(function() {
|
||||||
launchModalForm("{% url 'stock-export-options' %}", {
|
|
||||||
submit_text: '{% trans "Export" %}',
|
|
||||||
success: function(response) {
|
|
||||||
var url = "{% url 'stock-export' %}";
|
|
||||||
|
|
||||||
url += "?format=" + response.format;
|
exportStock({
|
||||||
url += "&cascade=" + response.cascade;
|
{% if location %}
|
||||||
|
location: {{ location.pk }}
|
||||||
{% if location %}
|
{% endif %}
|
||||||
url += "&location={{ location.id }}";
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
location.href = url;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ stock_urls = [
|
|||||||
|
|
||||||
url(r'^track/', include(stock_tracking_urls)),
|
url(r'^track/', include(stock_tracking_urls)),
|
||||||
|
|
||||||
url(r'^export-options/?', views.StockExportOptions.as_view(), name='stock-export-options'),
|
|
||||||
url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
|
url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
|
||||||
|
|
||||||
# Individual stock items
|
# Individual stock items
|
||||||
|
@ -378,38 +378,6 @@ class StockItemDeleteTestData(AjaxUpdateView):
|
|||||||
return self.renderJsonResponse(request, form, data)
|
return self.renderJsonResponse(request, form, data)
|
||||||
|
|
||||||
|
|
||||||
class StockExportOptions(AjaxView):
|
|
||||||
""" Form for selecting StockExport options """
|
|
||||||
|
|
||||||
model = StockLocation
|
|
||||||
ajax_form_title = _('Stock Export Options')
|
|
||||||
form_class = StockForms.ExportOptionsForm
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
|
|
||||||
self.request = request
|
|
||||||
|
|
||||||
fmt = request.POST.get('file_format', 'csv').lower()
|
|
||||||
cascade = str2bool(request.POST.get('include_sublocations', False))
|
|
||||||
|
|
||||||
# Format a URL to redirect to
|
|
||||||
url = reverse('stock-export')
|
|
||||||
|
|
||||||
url += '?format=' + fmt
|
|
||||||
url += '&cascade=' + str(cascade)
|
|
||||||
|
|
||||||
data = {
|
|
||||||
'form_valid': True,
|
|
||||||
'format': fmt,
|
|
||||||
'cascade': cascade
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.renderJsonResponse(self.request, self.form_class(), data=data)
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
return self.renderJsonResponse(request, self.form_class())
|
|
||||||
|
|
||||||
|
|
||||||
class StockExport(AjaxView):
|
class StockExport(AjaxView):
|
||||||
""" Export stock data from a particular location.
|
""" Export stock data from a particular location.
|
||||||
Returns a file containing stock information for that location.
|
Returns a file containing stock information for that location.
|
||||||
@ -471,11 +439,10 @@ class StockExport(AjaxView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if location:
|
if location:
|
||||||
# CHeck if locations should be cascading
|
# Check if locations should be cascading
|
||||||
cascade = str2bool(request.GET.get('cascade', True))
|
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
|
|
||||||
stock_items = StockItem.objects.all()
|
stock_items = StockItem.objects.all()
|
||||||
|
|
||||||
if part:
|
if part:
|
||||||
|
@ -252,6 +252,11 @@ function constructDeleteForm(fields, options) {
|
|||||||
*/
|
*/
|
||||||
function constructForm(url, options) {
|
function constructForm(url, options) {
|
||||||
|
|
||||||
|
// An "empty" form will be defined locally
|
||||||
|
if (url == null) {
|
||||||
|
constructFormBody({}, options);
|
||||||
|
}
|
||||||
|
|
||||||
// Save the URL
|
// Save the URL
|
||||||
options.url = url;
|
options.url = url;
|
||||||
|
|
||||||
@ -378,6 +383,11 @@ function constructFormBody(fields, options) {
|
|||||||
fields[field].placeholder = field_options.placeholder;
|
fields[field].placeholder = field_options.placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choices
|
||||||
|
if (field_options.choices) {
|
||||||
|
fields[field].choices = field_options.choices;
|
||||||
|
}
|
||||||
|
|
||||||
// Field prefix
|
// Field prefix
|
||||||
if (field_options.prefix) {
|
if (field_options.prefix) {
|
||||||
fields[field].prefix = field_options.prefix;
|
fields[field].prefix = field_options.prefix;
|
||||||
|
@ -20,6 +20,55 @@ function stockStatusCodes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Export stock table
|
||||||
|
*/
|
||||||
|
function exportStock(params={}) {
|
||||||
|
|
||||||
|
constructFormBody({}, {
|
||||||
|
title: '{% trans "Export Stock" %}',
|
||||||
|
fields: {
|
||||||
|
format: {
|
||||||
|
label: '{% trans "Format" %}',
|
||||||
|
help_text: '{% trans "Select file format" %}',
|
||||||
|
required: true,
|
||||||
|
type: 'choice',
|
||||||
|
value: 'csv',
|
||||||
|
choices: [
|
||||||
|
{ value: 'csv', display_name: 'CSV' },
|
||||||
|
{ value: 'tsv', display_name: 'TSV' },
|
||||||
|
{ value: 'xls', display_name: 'XLS' },
|
||||||
|
{ value: 'xlsx', display_name: 'XLSX' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
sublocations: {
|
||||||
|
label: '{% trans "Include Sublocations" %}',
|
||||||
|
help_text: '{% trans "Include stock items in sublocations" %}',
|
||||||
|
type: 'boolean',
|
||||||
|
value: 'true',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSubmit: function(fields, form_options) {
|
||||||
|
|
||||||
|
var format = getFormFieldValue('format', fields['format'], form_options);
|
||||||
|
var cascade = getFormFieldValue('sublocations', fields['sublocations'], form_options);
|
||||||
|
|
||||||
|
// Hide the modal
|
||||||
|
$(form_options.modal).modal('hide');
|
||||||
|
|
||||||
|
var url = `{% url "stock-export" %}?format=${format}&cascade=${cascade}`;
|
||||||
|
|
||||||
|
for (var key in params) {
|
||||||
|
url += `&${key}=${params[key]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(url);
|
||||||
|
location.href = url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform stock adjustments
|
* Perform stock adjustments
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user