mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Add ability to include test results from "installed items" in table
This commit is contained in:
parent
46892f9288
commit
dfa3bbf655
@ -1105,7 +1105,6 @@ class StockItemTestResultList(generics.ListCreateAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
filter_fields = [
|
filter_fields = [
|
||||||
'stock_item',
|
|
||||||
'test',
|
'test',
|
||||||
'user',
|
'user',
|
||||||
'result',
|
'result',
|
||||||
@ -1114,6 +1113,38 @@ class StockItemTestResultList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
ordering = 'date'
|
ordering = 'date'
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
|
||||||
|
params = self.request.query_params
|
||||||
|
|
||||||
|
queryset = super().filter_queryset(queryset)
|
||||||
|
|
||||||
|
# Filter by stock item
|
||||||
|
item = params.get('stock_item', None)
|
||||||
|
|
||||||
|
if item is not None:
|
||||||
|
try:
|
||||||
|
item = StockItem.objects.get(pk=item)
|
||||||
|
|
||||||
|
items = [item]
|
||||||
|
|
||||||
|
# Do we wish to also include test results for 'installed' items?
|
||||||
|
include_installed = str2bool(params.get('include_installed', False))
|
||||||
|
|
||||||
|
if include_installed:
|
||||||
|
# Include items which are installed "underneath" this item
|
||||||
|
# Note that this function is recursive!
|
||||||
|
installed_items = item.get_installed_items(cascade=True)
|
||||||
|
|
||||||
|
items += [it for it in installed_items]
|
||||||
|
|
||||||
|
queryset = queryset.filter(stock_item__in=items)
|
||||||
|
|
||||||
|
except (ValueError, StockItem.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
def get_serializer(self, *args, **kwargs):
|
def get_serializer(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))
|
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))
|
||||||
|
@ -1331,14 +1331,27 @@ function loadStockTestResultsTable(table, options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Once the test template data are loaded, query for test results
|
// Once the test template data are loaded, query for test results
|
||||||
inventreeGet(
|
|
||||||
'{% url "api-stock-test-result-list" %}',
|
var filters = loadTableFilters(filterKey);
|
||||||
{
|
|
||||||
|
var query_params = {
|
||||||
stock_item: options.stock_item,
|
stock_item: options.stock_item,
|
||||||
user_detail: true,
|
user_detail: true,
|
||||||
attachment_detail: true,
|
attachment_detail: true,
|
||||||
ordering: '-date',
|
ordering: '-date',
|
||||||
},
|
};
|
||||||
|
|
||||||
|
if ('result' in filters) {
|
||||||
|
query_params.result = filters.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('include_installed' in filters) {
|
||||||
|
query_params.include_installed = filters.include_installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
inventreeGet(
|
||||||
|
'{% url "api-stock-test-result-list" %}',
|
||||||
|
query_params,
|
||||||
{
|
{
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
// Iterate through the returned test data
|
// Iterate through the returned test data
|
||||||
|
@ -265,7 +265,16 @@ function getAvailableTableFilters(tableKey) {
|
|||||||
|
|
||||||
// Filters for the 'stock test' table
|
// Filters for the 'stock test' table
|
||||||
if (tableKey == 'stocktests') {
|
if (tableKey == 'stocktests') {
|
||||||
return {};
|
return {
|
||||||
|
result: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Test Passed" %}',
|
||||||
|
},
|
||||||
|
include_installed: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Include Installed Items" %}',
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters for the 'part test template' table
|
// Filters for the 'part test template' table
|
||||||
|
Loading…
x
Reference in New Issue
Block a user