mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Merge pull request #2452 from SchrodingersGat/bom-export-form-fixes
BOM export form fixes
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
/* globals
|
||||
constructForm,
|
||||
exportFormatOptions,
|
||||
imageHoverIcon,
|
||||
inventreeGet,
|
||||
inventreePut,
|
||||
@ -14,6 +15,8 @@
|
||||
*/
|
||||
|
||||
/* exported
|
||||
downloadBomTemplate,
|
||||
exportBom,
|
||||
newPartFromBomWizard,
|
||||
loadBomTable,
|
||||
loadUsedInTable,
|
||||
@ -21,12 +24,121 @@
|
||||
removeColFromBomWizard,
|
||||
*/
|
||||
|
||||
/* BOM management functions.
|
||||
* Requires follwing files to be loaded first:
|
||||
* - api.js
|
||||
* - part.js
|
||||
* - modals.js
|
||||
function downloadBomTemplate(options={}) {
|
||||
|
||||
var format = options.format;
|
||||
|
||||
if (!format) {
|
||||
format = inventreeLoad('bom-export-format', 'csv');
|
||||
}
|
||||
|
||||
constructFormBody({}, {
|
||||
title: '{% trans "Download BOM Template" %}',
|
||||
fields: {
|
||||
format: {
|
||||
label: '{% trans "Format" %}',
|
||||
help_text: '{% trans "Select file format" %}',
|
||||
required: true,
|
||||
type: 'choice',
|
||||
value: format,
|
||||
choices: exportFormatOptions(),
|
||||
}
|
||||
},
|
||||
onSubmit: function(fields, opts) {
|
||||
var format = getFormFieldValue('format', fields['format'], opts);
|
||||
|
||||
// Save the format for next time
|
||||
inventreeSave('bom-export-format', format);
|
||||
|
||||
// Hide the modal
|
||||
$(opts.modal).modal('hide');
|
||||
|
||||
// Download the file
|
||||
location.href = `{% url "bom-upload-template" %}?format=${format}`;
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export BOM (Bill of Materials) for the specified Part instance
|
||||
*/
|
||||
function exportBom(part_id, options={}) {
|
||||
|
||||
constructFormBody({}, {
|
||||
title: '{% trans "Export BOM" %}',
|
||||
fields: {
|
||||
format: {
|
||||
label: '{% trans "Format" %}',
|
||||
help_text: '{% trans "Select file format" %}',
|
||||
required: true,
|
||||
type: 'choice',
|
||||
value: inventreeLoad('bom-export-format', 'csv'),
|
||||
choices: exportFormatOptions(),
|
||||
},
|
||||
cascading: {
|
||||
label: '{% trans "Cascading" %}',
|
||||
help_text: '{% trans "Download cascading / multi-level BOM" %}',
|
||||
type: 'boolean',
|
||||
value: inventreeLoad('bom-export-cascading', true),
|
||||
},
|
||||
levels: {
|
||||
label: '{% trans "Levels" %}',
|
||||
help_text: '{% trans "Select maximum number of BOM levels to export (0 = all levels)" %}',
|
||||
type: 'integer',
|
||||
value: 0,
|
||||
min_value: 0,
|
||||
},
|
||||
parameter_data: {
|
||||
label: '{% trans "Include Parameter Data" %}',
|
||||
help_text: '{% trans "Include part parameter data in exported BOM" %}',
|
||||
type: 'boolean',
|
||||
value: inventreeLoad('bom-export-parameter_data', false),
|
||||
},
|
||||
stock_data: {
|
||||
label: '{% trans "Include Stock Data" %}',
|
||||
help_text: '{% trans "Include part stock data in exported BOM" %}',
|
||||
type: 'boolean',
|
||||
value: inventreeLoad('bom-export-stock_data', false),
|
||||
},
|
||||
manufacturer_data: {
|
||||
label: '{% trans "Include Manufacturer Data" %}',
|
||||
help_text: '{% trans "Include part manufacturer data in exported BOM" %}',
|
||||
type: 'boolean',
|
||||
value: inventreeLoad('bom-export-manufacturer_data', false),
|
||||
},
|
||||
supplier_data: {
|
||||
label: '{% trans "Include Supplier Data" %}',
|
||||
help_text: '{% trans "Include part supplier data in exported BOM" %}',
|
||||
type: 'boolean',
|
||||
value: inventreeLoad('bom-export-supplier_data', false),
|
||||
}
|
||||
},
|
||||
onSubmit: function(fields, opts) {
|
||||
|
||||
// Extract values from the form
|
||||
var field_names = ['format', 'cascading', 'levels', 'parameter_data', 'stock_data', 'manufacturer_data', 'supplier_data'];
|
||||
|
||||
var url = `/part/${part_id}/bom-download/?`;
|
||||
|
||||
field_names.forEach(function(fn) {
|
||||
var val = getFormFieldValue(fn, fields[fn], opts);
|
||||
|
||||
// Update user preferences
|
||||
inventreeSave(`bom-export-${fn}`, val);
|
||||
|
||||
url += `${fn}=${val}&`;
|
||||
});
|
||||
|
||||
$(opts.modal).modal('hide');
|
||||
|
||||
// Redirect to the BOM file download
|
||||
location.href = url;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function bomItemFields() {
|
||||
|
@ -811,7 +811,9 @@ function updateFieldValue(name, value, field, options) {
|
||||
|
||||
switch (field.type) {
|
||||
case 'boolean':
|
||||
el.prop('checked', value);
|
||||
if (value == true || value.toString().toLowerCase() == 'true') {
|
||||
el.prop('checked');
|
||||
}
|
||||
break;
|
||||
case 'related field':
|
||||
// Clear?
|
||||
@ -2034,8 +2036,15 @@ function constructInputOptions(name, classes, type, parameters) {
|
||||
}
|
||||
|
||||
if (parameters.value != null) {
|
||||
// Existing value?
|
||||
opts.push(`value='${parameters.value}'`);
|
||||
if (parameters.type == 'boolean') {
|
||||
// Special consideration of a boolean (checkbox) value
|
||||
if (parameters.value == true || parameters.value.toString().toLowerCase() == 'true') {
|
||||
opts.push('checked');
|
||||
}
|
||||
} else {
|
||||
// Existing value?
|
||||
opts.push(`value='${parameters.value}'`);
|
||||
}
|
||||
} else if (parameters.default != null) {
|
||||
// Otherwise, a defualt value?
|
||||
opts.push(`value='${parameters.default}'`);
|
||||
|
Reference in New Issue
Block a user