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', field: 'received',
switchable: false, switchable: false,
title: '{% trans "Received" %}', title: '{% trans "Received" %}',

View File

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

View File

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