mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add Date input for table filter (#4067)
* Add Date input for table filter * Update filters.js * Update filters.js * Expiry date filter on stock item * JS whitespace * Timezone from JS * Move to timestamp timezoned * Revert to YYYY-MM-DD iso format * Remove setting/ getFilterSettings from addTableFilter
This commit is contained in:
parent
d50bf60826
commit
6a0efb0365
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
|
|
||||||
# InvenTree API version
|
# InvenTree API version
|
||||||
INVENTREE_API_VERSION = 86
|
INVENTREE_API_VERSION = 87
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Increment this API version number whenever there is a significant change to the API that any clients need to know about
|
Increment this API version number whenever there is a significant change to the API that any clients need to know about
|
||||||
|
v87 -> 2023-01-04 : https://github.com/inventree/InvenTree/pull/4067
|
||||||
|
- Add API date filter for stock table on Expiry date
|
||||||
|
|
||||||
v86 -> 2022-12-22 : https://github.com/inventree/InvenTree/pull/4069
|
v86 -> 2022-12-22 : https://github.com/inventree/InvenTree/pull/4069
|
||||||
- Adds API endpoints for part stocktake
|
- Adds API endpoints for part stocktake
|
||||||
|
@ -830,7 +830,22 @@ class StockList(APIDownloadMixin, ListCreateDestroyAPIView):
|
|||||||
queryset = queryset.filter(StockItem.EXPIRED_FILTER)
|
queryset = queryset.filter(StockItem.EXPIRED_FILTER)
|
||||||
else:
|
else:
|
||||||
queryset = queryset.exclude(StockItem.EXPIRED_FILTER)
|
queryset = queryset.exclude(StockItem.EXPIRED_FILTER)
|
||||||
|
# Filter by 'expiry date'
|
||||||
|
expired_date_lte = params.get('expiry_date_lte', None)
|
||||||
|
if expired_date_lte is not None:
|
||||||
|
try:
|
||||||
|
date_lte = datetime.fromisoformat(expired_date_lte)
|
||||||
|
queryset = queryset.filter(expiry_date__lte=date_lte)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
expiry_date_gte = params.get('expiry_date_gte', None)
|
||||||
|
if expiry_date_gte is not None:
|
||||||
|
try:
|
||||||
|
date_gte = datetime.fromisoformat(expiry_date_gte)
|
||||||
|
queryset = queryset.filter(expiry_date__gte=date_gte)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
pass
|
||||||
# Filter by 'stale' status
|
# Filter by 'stale' status
|
||||||
stale = params.get('stale', None)
|
stale = params.get('stale', None)
|
||||||
|
|
||||||
|
@ -182,6 +182,8 @@ function getFilterOptionList(tableKey, filterKey) {
|
|||||||
value: '{% trans "false" %}',
|
value: '{% trans "false" %}',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
} else if (settings.type == 'date') {
|
||||||
|
return 'date';
|
||||||
} else if ('options' in settings) {
|
} else if ('options' in settings) {
|
||||||
return settings.options;
|
return settings.options;
|
||||||
}
|
}
|
||||||
@ -233,6 +235,8 @@ function generateFilterInput(tableKey, filterKey) {
|
|||||||
// A 'null' options list means that a simple text-input dialog should be used
|
// A 'null' options list means that a simple text-input dialog should be used
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
html = `<input class='form-control filter-input' id='${id}' name='value'></input>`;
|
html = `<input class='form-control filter-input' id='${id}' name='value'></input>`;
|
||||||
|
} else if (options == 'date') {
|
||||||
|
html = `<input type='date' class='dateinput form-control filter-input' id='${id}' name='value'></input>`;
|
||||||
} else {
|
} else {
|
||||||
// Return a 'select' input with the available values
|
// Return a 'select' input with the available values
|
||||||
html = `<select class='form-control filter-input' id='${id}' name='value'>`;
|
html = `<select class='form-control filter-input' id='${id}' name='value'>`;
|
||||||
|
@ -280,6 +280,14 @@ function getAvailableTableFilters(tableKey) {
|
|||||||
title: '{% trans "Has purchase price" %}',
|
title: '{% trans "Has purchase price" %}',
|
||||||
description: '{% trans "Show stock items which have a purchase price set" %}',
|
description: '{% trans "Show stock items which have a purchase price set" %}',
|
||||||
},
|
},
|
||||||
|
expiry_date_lte: {
|
||||||
|
type: 'date',
|
||||||
|
title: '{% trans "Expiry Date before" %}',
|
||||||
|
},
|
||||||
|
expiry_date_gte: {
|
||||||
|
type: 'date',
|
||||||
|
title: '{% trans "Expiry Date after" %}',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Optional filters if stock expiry functionality is enabled
|
// Optional filters if stock expiry functionality is enabled
|
||||||
|
Loading…
Reference in New Issue
Block a user