diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index ff4488f683..2f81b68a75 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -832,6 +832,7 @@ def inheritors(cls): """Return all classes that are subclasses from the supplied cls.""" subcls = set() work = [cls] + while work: parent = work.pop() for child in parent.__subclasses__(): diff --git a/InvenTree/generic/states/test_transition.py b/InvenTree/generic/states/test_transition.py index 28c112c97f..43b7687918 100644 --- a/InvenTree/generic/states/test_transition.py +++ b/InvenTree/generic/states/test_transition.py @@ -4,6 +4,13 @@ from InvenTree.unit_test import InvenTreeTestCase from .transition import StateTransitionMixin, TransitionMethod, storage +# Global variables to determine which transition classes raises an exception +global raise_storage +global raise_function + +raise_storage = False +raise_function = False + class MyPrivateError(NotImplementedError): """Error for testing purposes.""" @@ -16,6 +23,7 @@ def dflt(*args, **kwargs): def _clean_storage(refs): """Clean the storage.""" + for ref in refs: del ref storage.collect() @@ -38,9 +46,20 @@ class TransitionTests(InvenTreeTestCase): def test_storage(self): """Ensure that the storage collection mechanism works.""" + global raise_storage + global raise_function + + raise_storage = True + raise_function = False + class RaisingImplementation(TransitionMethod): def transition(self, *args, **kwargs): - raise MyPrivateError('RaisingImplementation') + """Custom transition method.""" + + global raise_storage + + if raise_storage: + raise MyPrivateError('RaisingImplementation') # Ensure registering works storage.collect() @@ -58,6 +77,12 @@ class TransitionTests(InvenTreeTestCase): def test_function(self): """Ensure that a TransitionMethod's function is called.""" + global raise_storage + global raise_function + + raise_storage = False + raise_function = True + # Setup class ValidImplementationNoEffect(TransitionMethod): def transition(self, *args, **kwargs): diff --git a/InvenTree/generic/states/transition.py b/InvenTree/generic/states/transition.py index 02911ac658..882ace3ebb 100644 --- a/InvenTree/generic/states/transition.py +++ b/InvenTree/generic/states/transition.py @@ -71,6 +71,7 @@ class StateTransitionMixin: instance: Object instance default_action: Default action to be taken if none of the transitions returns a boolean true value """ + # Check if there is a custom override function for this transition for override in storage.list: rslt = override.transition(current_state, target_state, instance, default_action, **kwargs)