Update BOM table display

This commit is contained in:
Oliver Walters 2021-06-01 14:17:31 +10:00
parent 0bd0e57f16
commit 9f407df15a
5 changed files with 24 additions and 14 deletions

View File

@ -827,7 +827,7 @@ class BomList(generics.ListCreateAPIView):
if variants is not None:
variants = str2bool(variants)
queryset = queryset.filter(allow_variants=variants)
queryset = queryset.filter(allow_variants=variants)
# Filter by part?
part = params.get('part', None)

View File

@ -352,6 +352,7 @@ class EditBomItemForm(HelperForm):
'reference',
'overage',
'note',
'allow_variants',
'inherited',
'optional',
]

View File

@ -285,11 +285,18 @@ function loadBomTable(table, options) {
title: '{% trans "Optional" %}',
searchable: false,
formatter: function(value) {
if (value == '1') return '{% trans "true" %}';
if (value == '0') return '{% trans "false" %}';
return yesNoLabel(value);
}
});
cols.push({
field: 'allow_variants',
title: '{% trans "Allow Variants" %}',
formatter: function(value) {
return yesNoLabel(value);
}
})
cols.push({
field: 'inherited',
title: '{% trans "Inherited" %}',
@ -297,7 +304,7 @@ function loadBomTable(table, options) {
formatter: function(value, row, index, field) {
// This BOM item *is* inheritable, but is defined for this BOM
if (!row.inherited) {
return "-";
return yesNoLabel(false);
} else if (row.part == options.parent_id) {
return '{% trans "Inherited" %}';
} else {

View File

@ -5,6 +5,14 @@
* Requires api.js to be loaded first
*/
function yesNoLabel(value) {
if (value) {
return `<span class='label label-green'>{% trans "YES" %}</span>`;
} else {
return `<span class='label label-yellow'>{% trans "NO" %}</span>`;
}
}
function toggleStar(options) {
/* Toggle the 'starred' status of a part.
* Performs AJAX queries and updates the display on the button.
@ -662,16 +670,6 @@ function loadPartCategoryTable(table, options) {
});
}
function yesNoLabel(value) {
if (value) {
return `<span class='label label-green'>{% trans "YES" %}</span>`;
} else {
return `<span class='label label-yellow'>{% trans "NO" %}</span>`;
}
}
function loadPartTestTemplateTable(table, options) {
/*
* Load PartTestTemplate table.

View File

@ -49,6 +49,10 @@ function getAvailableTableFilters(tableKey) {
inherited: {
type: 'bool',
title: '{% trans "Inherited" %}',
},
allow_variants: {
type: 'bool',
title: '{% trans "Allow Variant Stock" %}',
}
};
}