mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 21:45:39 +00:00
Improve table for displaying what parts a particular part is "used in"
This commit is contained in:
@ -427,4 +427,86 @@ function loadBomTable(table, options) {
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function loadUsedInTable(table, options) {
|
||||
/* Load a table which displays all the parts that the given part is used in.
|
||||
*/
|
||||
|
||||
var params = {
|
||||
sub_part: options.part_id,
|
||||
ordering: 'name',
|
||||
}
|
||||
|
||||
if (options.part_detail) {
|
||||
params.part_detail = true;
|
||||
}
|
||||
|
||||
if (options.sub_part_detail) {
|
||||
params.sub_part_detail = true;
|
||||
}
|
||||
|
||||
var filters = {};
|
||||
|
||||
if (!options.disableFilters) {
|
||||
filters = loadTableFilters("usedin");
|
||||
}
|
||||
|
||||
for (var key in params) {
|
||||
filters[key] = params[key];
|
||||
}
|
||||
|
||||
setupFilterList("usedin", $(table));
|
||||
|
||||
// Columns to display in the table
|
||||
var cols = [
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
switchable: false,
|
||||
},
|
||||
{
|
||||
field: 'part_detail.full_name',
|
||||
title: '{% trans "Part" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
var link = `/part/${row.part}/bom/`;
|
||||
var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(row.part_detail.full_name, link);
|
||||
|
||||
if (!row.part_detail.active) {
|
||||
html += "<span class='label label-warning' style='float: right;'>{% trans 'INACTIVE' %}</span>";
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'part_detail.description',
|
||||
title: '{% trans "Description" %}',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'quantity',
|
||||
title: '{% trans "Uses" %}',
|
||||
formatter: function(value, row, index, field) {
|
||||
return parseFloat(value);
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
// Load the table
|
||||
$(table).inventreeTable({
|
||||
url: "{% url 'api-bom-list' %}",
|
||||
formatNoMatches: function() {
|
||||
return '{% trans "No matching parts found" %}';
|
||||
},
|
||||
columns: cols,
|
||||
showColumns: true,
|
||||
sortable: true,
|
||||
serach: true,
|
||||
queryParams: filters,
|
||||
original: params,
|
||||
});
|
||||
}
|
@ -11,6 +11,30 @@ function getAvailableTableFilters(tableKey) {
|
||||
|
||||
tableKey = tableKey.toLowerCase();
|
||||
|
||||
// Filters for Bill of Materials table
|
||||
if (tableKey == "bom") {
|
||||
return {
|
||||
sub_part_trackable: {
|
||||
type: 'bool',
|
||||
title: '{% trans "Trackable Part" %}'
|
||||
},
|
||||
validated: {
|
||||
type: 'bool',
|
||||
title: '{% trans "Validated" %}',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Filters for the "used in" table
|
||||
if (tableKey == 'usedin') {
|
||||
return {
|
||||
'part_active': {
|
||||
type: 'bool',
|
||||
title: '{% trans "Active" %}',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Filters for the "customer stock" table (really a subset of "stock")
|
||||
if (tableKey == "customerstock") {
|
||||
return {
|
||||
|
Reference in New Issue
Block a user