diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index ba3f3525d5..872c4fe458 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -4,6 +4,15 @@ from wsgiref.util import FileWrapper from django.http import StreamingHttpResponse +def str2bool(text, test=True): + """ Test if a string 'looks' like a boolean value + """ + if test: + return str(text).lower() in ['1', 'y', 'yes', 't', 'true', 'ok', ] + else: + return str(text).lower() in ['0', 'n', 'no', 'none', 'f', 'false',] + + def WrapWithQuotes(text): # TODO - Make this better if not text.startswith('"'): diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index 4c25be2fe6..b7468cd7cb 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -183,7 +183,7 @@ def FilterChildren(queryset, parent): if not parent: return queryset - elif str(parent).lower() in ['none', 'false', 'null', 'top', '0']: + elif str2bool(parent, False): return queryset.filter(parent=None) else: try: