Fixes for ordering of stock table

This commit is contained in:
Oliver 2021-08-26 08:24:31 +10:00
parent 212a7eeed1
commit bad246bca6
3 changed files with 29 additions and 7 deletions

View File

@ -383,7 +383,7 @@ $("#po-table").inventreeTable({
}
},
{
sortable: true,
sortable: false,
field: 'received',
switchable: false,
title: '{% trans "Received" %}',

View File

@ -43,6 +43,7 @@ from .serializers import StockItemTestResultSerializer
from InvenTree.views import TreeSerializer
from InvenTree.helpers import str2bool, isNull
from InvenTree.api import AttachmentMixin
from InvenTree.filters import InvenTreeOrderingFilter
from decimal import Decimal, InvalidOperation
@ -882,10 +883,16 @@ class StockList(generics.ListCreateAPIView):
filter_backends = [
DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter,
InvenTreeOrderingFilter,
]
ordering_field_aliases = {
'SKU': 'supplier_part__SKU',
}
ordering_fields = [
'batch',
'location',
'part__name',
'part__IPN',
'updated',
@ -893,10 +900,13 @@ class StockList(generics.ListCreateAPIView):
'expiry_date',
'quantity',
'status',
'SKU',
]
ordering = [
'part__name'
'part__name',
'quantity',
'location',
]
search_fields = [

View File

@ -921,8 +921,10 @@ function loadStockTable(table, options) {
return renderLink(text, link);
}
},
{
});
col = {
field: 'supplier_part',
title: '{% trans "Supplier Part" %}',
visible: params['supplier_part_detail'] || false,
@ -944,15 +946,25 @@ function loadStockTable(table, options) {
return renderLink(text, link);
}
});
};
if (!options.params.ordering) {
col.sortable = true;
col.sortName = 'SKU';
}
columns.push(col);
col = {
field: 'purchase_price_string',
title: '{% trans "Purchase Price" %}',
};
if (!options.params.ordering) {
col['sortable'] = true;
col.sortable = true;
col.sortName = 'purchase_price';
};
columns.push(col);
columns.push({