2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

Refactor StockExportOptions form

This commit is contained in:
Oliver
2021-07-19 17:23:18 +10:00
parent e7d9485c16
commit efb4f194b6
9 changed files with 71 additions and 105 deletions

View File

@ -252,6 +252,11 @@ function constructDeleteForm(fields, options) {
*/
function constructForm(url, options) {
// An "empty" form will be defined locally
if (url == null) {
constructFormBody({}, options);
}
// Save the URL
options.url = url;
@ -378,6 +383,11 @@ function constructFormBody(fields, options) {
fields[field].placeholder = field_options.placeholder;
}
// Choices
if (field_options.choices) {
fields[field].choices = field_options.choices;
}
// Field prefix
if (field_options.prefix) {
fields[field].prefix = field_options.prefix;

View File

@ -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
*/