diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 8c5d59181d..3f65312691 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -19,6 +19,20 @@ from .version import inventreeVersion, inventreeInstanceName from .settings import MEDIA_URL, STATIC_URL +def generateTestKey(test_name): + """ + Generate a test 'key' for a given test name. + This must not have spaces as it will be used for dict lookup in a template. + + Tests must be named such that they will have unique keys. + """ + + key = test_name.strip().lower() + key = key.replace(" ", "") + + return key + + def getMediaUrl(filename): """ Return the qualified access path for the given file, diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index a73c7e0a76..6b29c6e5fc 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -962,7 +962,8 @@ class StockItem(MPTTModel): result_map = {} for result in results: - result_map[result.test] = result + key = helpers.generateTestKey(result.test) + result_map[key] = result return result_map diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index 8fce455a97..cd927e0251 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -429,5 +429,6 @@ class TestResultTest(StockTest): self.assertEqual(len(result_map), 3) - for test in ['Firmware Version', 'Settings Checksum', 'Temperature Test']: + # Keys are all lower-case and do not contain spaces + for test in ['firmwareversion', 'settingschecksum', 'temperaturetest']: self.assertIn(test, result_map.keys())