Coverage for src/backend/InvenTree/plugin/base/action/mixins.py: 52%

19 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 17:47 +0000

1"""Plugin mixin classes for action plugin.""" 

2 

3from plugin import PluginMixinEnum 

4 

5 

6class ActionMixin: 

7 """Mixin that enables custom actions.""" 

8 

9 ACTION_NAME = '' 

10 

11 class MixinMeta: 

12 """Meta options for this mixin.""" 

13 

14 MIXIN_NAME = 'Actions' 

15 

16 def __init__(self): 

17 """Register mixin.""" 

18 super().__init__() 

19 self.add_mixin(PluginMixinEnum.ACTION, True, __class__) 

20 

21 def action_name(self): 

22 """Action name for this plugin. 

23 

24 If the ACTION_NAME parameter is empty, 

25 uses the NAME instead. 

26 """ 

27 if self.ACTION_NAME: 

28 return self.ACTION_NAME 

29 return self.name 

30 

31 def perform_action(self, user=None, data=None): 

32 """Override this method to perform the action!""" 

33 

34 def get_result(self, user=None, data=None): 

35 """Result of the action?""" 

36 # Re-implement this for cutsom actions 

37 return False 

38 

39 def get_info(self, user=None, data=None): 

40 """Extra info? 

41 

42 Can be a string / dict / etc 

43 """ 

44 return None 

45 

46 def get_response(self, user=None, data=None): 

47 """Return a response. 

48 

49 Default implementation is a simple response which can be overridden. 

50 """ 

51 return { 

52 'action': self.action_name(), 

53 'result': self.get_result(user, data), 

54 'info': self.get_info(user, data), 

55 }