diff --git a/InvenTree/InvenTree/static/script/inventree/filters.js b/InvenTree/InvenTree/static/script/inventree/filters.js index 0ae09b29ad..cadc1021f5 100644 --- a/InvenTree/InvenTree/static/script/inventree/filters.js +++ b/InvenTree/InvenTree/static/script/inventree/filters.js @@ -97,51 +97,6 @@ function addTableFilter(tableKey, filterKey, filterValue) { } -/** - * Return the custom filtering options available for a particular table - * - * @param {*} tableKey - string key lookup for the table - */ -function getAvailableTableFilters(tableKey) { - - tableKey = tableKey.toLowerCase(); - - // Filters for the "Stock" table - if (tableKey == 'stock') { - return { - 'cascade': { - 'type': 'bool', - 'description': 'Include stock in sublocations', - 'title': 'Include sublocations', - }, - 'active': { - 'type': 'bool', - 'title': 'Acitve parts', - 'description': 'Show stock for active parts', - }, - 'status': { - 'options': { - 'OK': 10, - 'ATTENTION': 50, - 'DAMAGED': 55, - 'DESTROYED': 60, - 'LOST': 70 - }, - 'title': 'Stock status', - 'description': 'Stock status', - }, - 'test': { - title: 'A test parameter', - }, - }; - } - - - // Finally, no matching key - return {}; -} - - /* * Return a list of the "available" filters for a given table key. * A filter is "available" if it is not already being used to filter the table. @@ -248,7 +203,7 @@ function generateFilterInput(tableKey, filterKey) { html += ``; } - + return html; } diff --git a/InvenTree/InvenTree/status_codes.py b/InvenTree/InvenTree/status_codes.py index cbc9f3565f..7037ccde65 100644 --- a/InvenTree/InvenTree/status_codes.py +++ b/InvenTree/InvenTree/status_codes.py @@ -2,6 +2,26 @@ from django.utils.translation import ugettext as _ class StatusCode: + """ + Base class for representing a set of StatusCodes. + This is used to map a set of integer values to text. + """ + + @classmethod + def list(cls): + """ + Return the StatusCode options as a list of mapped key / value items + """ + + codes = [] + + for key in cls.options.keys(): + codes.append({ + 'key': key, + 'value': cls.options[key] + }) + + return codes @classmethod def items(cls): diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index e68e9c23dc..51987df4b7 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -7,10 +7,22 @@ from InvenTree import version from InvenTree.helpers import decimal2string from common.models import InvenTreeSetting +from InvenTree.status_codes import OrderStatus, StockStatus, BuildStatus register = template.Library() +@register.simple_tag(takes_context=True) +def load_status_codes(context): + + context['order_status_codes'] = OrderStatus.list() + context['stock_status_codes'] = StockStatus.list() + context['build_status_codes'] = BuildStatus.list() + + # Need to return something as the result is rendered to the page + return '' + + @register.simple_tag() def decimal(x, *args, **kwargs): """ Simplified rendering of a decimal number """ diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index 58f72adc05..872d704c06 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -1,4 +1,5 @@ {% load static %} +{% load i18n %} @@ -116,7 +117,10 @@ InvenTree {% block js_load %} {% endblock %} +{% include "table_filters.html" %} + {% block js %} diff --git a/InvenTree/templates/table_filters.html b/InvenTree/templates/table_filters.html new file mode 100644 index 0000000000..d908dfa38c --- /dev/null +++ b/InvenTree/templates/table_filters.html @@ -0,0 +1,40 @@ +{% load i18n %} +{% load inventree_extras %} + + \ No newline at end of file