mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Instead of creating a custom filter for "latest" parts,
simply make use of the existing "ordering" query as part of DRF
This commit is contained in:
parent
a218b6b351
commit
eaf42b8abe
@ -405,13 +405,6 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
except (ValueError, Part.DoesNotExist):
|
except (ValueError, Part.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Filter by latest part creation date
|
|
||||||
latest_parts = params.get('latest_parts', None)
|
|
||||||
|
|
||||||
if latest_parts is not None:
|
|
||||||
# Get the last 5 created parts
|
|
||||||
queryset = queryset.order_by('-creation_date')[:5]
|
|
||||||
|
|
||||||
# Filter invalid BOMs
|
# Filter invalid BOMs
|
||||||
bom_invalid = params.get('bom_invalid', None)
|
bom_invalid = params.get('bom_invalid', None)
|
||||||
|
|
||||||
@ -514,6 +507,17 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
queryset = queryset.filter(pk__in=parts_need_stock)
|
queryset = queryset.filter(pk__in=parts_need_stock)
|
||||||
|
|
||||||
|
# Limit choices
|
||||||
|
limit = params.get('limit', None)
|
||||||
|
|
||||||
|
if limit is not None:
|
||||||
|
try:
|
||||||
|
limit = int(limit)
|
||||||
|
if limit > 0:
|
||||||
|
queryset = queryset[:limit]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
@ -539,6 +543,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
ordering_fields = [
|
ordering_fields = [
|
||||||
'name',
|
'name',
|
||||||
|
'creation_date',
|
||||||
]
|
]
|
||||||
|
|
||||||
# Default ordering
|
# Default ordering
|
||||||
|
@ -55,10 +55,12 @@ InvenTree | Index
|
|||||||
|
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
loadPartTable("#latest-parts-table", "{% url 'api-part-list' %}", {
|
loadSimplePartTable("#latest-parts-table", "{% url 'api-part-list' %}", {
|
||||||
params: {
|
params: {
|
||||||
"latest_parts": true,
|
ordering: "-creation_date",
|
||||||
}
|
limit: 10,
|
||||||
|
},
|
||||||
|
name: 'latest_parts',
|
||||||
});
|
});
|
||||||
|
|
||||||
loadPartTable("#starred-parts-table", "{% url 'api-part-list' %}", {
|
loadPartTable("#starred-parts-table", "{% url 'api-part-list' %}", {
|
||||||
|
@ -155,6 +155,14 @@ function loadPartVariantTable(table, partId, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadSimplePartTable(table, url, options={}) {
|
||||||
|
|
||||||
|
options.disableFilters = true;
|
||||||
|
|
||||||
|
loadPartTable(table, url, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function loadPartTable(table, url, options={}) {
|
function loadPartTable(table, url, options={}) {
|
||||||
/* Load part listing data into specified table.
|
/* Load part listing data into specified table.
|
||||||
*
|
*
|
||||||
@ -332,7 +340,7 @@ function loadPartTable(table, url, options={}) {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
name: 'part',
|
name: options.name || 'part',
|
||||||
original: params,
|
original: params,
|
||||||
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
|
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
|
||||||
columns: columns,
|
columns: columns,
|
||||||
|
Loading…
Reference in New Issue
Block a user