Coverage for src/backend/InvenTree/plugin/base/integration/ReportMixin.py: 80%

10 statements  

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

1"""Plugin mixin class for ReportContextMixin.""" 

2 

3from plugin import PluginMixinEnum 

4 

5 

6class ReportMixin: 

7 """Mixin which provides additional context to generated reports. 

8 

9 This plugin mixin acts as a "shim" when generating reports, 

10 can can add extra context data to a report template. 

11 

12 Useful for custom report generation where the report template 

13 needs some extra information which is not provided by default, 

14 or some complex logic to generate the report. 

15 """ 

16 

17 class MixinMeta: 

18 """Meta options for this mixin.""" 

19 

20 MIXIN_NAME = 'ReportContext' 

21 

22 def __init__(self): 

23 """Register mixin.""" 

24 super().__init__() 

25 self.add_mixin(PluginMixinEnum.REPORT, True, __class__) 

26 

27 def add_report_context(self, report_instance, model_instance, user, context): 

28 """Add extra context to the provided report instance. 

29 

30 By default, this method does nothing. 

31 

32 Args: 

33 report_instance: The report instance to add context to 

34 model_instance: The model instance which initiated the report generation 

35 user: The user to associate with the generated report 

36 context: The context dictionary to add to 

37 """ 

38 

39 def add_label_context(self, label_instance, model_instance, user, context): 

40 """Add extra context to the provided label instance. 

41 

42 By default, this method does nothing. 

43 

44 Args: 

45 label_instance: The label instance to add context to 

46 model_instance: The model instance which initiated the label generation 

47 user: The user to associate with the generated label 

48 context: The context dictionary to add to 

49 """ 

50 

51 def report_callback(self, template, instance, report, user, **kwargs): 

52 """Callback function called after a report is generated. 

53 

54 Arguments: 

55 template: The ReportTemplate model 

56 instance: The instance of the target model 

57 report: The generated report object 

58 user: The user to associate with the generated report 

59 

60 The default implementation does nothing. 

61 """