Coverage for src/backend/InvenTree/plugin/samples/integration/report_plugin_sample.py: 0%
16 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Sample plugin for extending reporting functionality."""
3import random
5from plugin import InvenTreePlugin
6from plugin.mixins import ReportMixin
9class SampleReportPlugin(ReportMixin, InvenTreePlugin):
10 """Sample plugin which provides extra context data to a report."""
12 NAME = 'Sample Report Plugin'
13 SLUG = 'samplereport'
14 TITLE = 'Sample Report Plugin'
15 DESCRIPTION = 'A sample plugin which provides extra context data to a report'
16 VERSION = '1.0'
18 def some_custom_function(self):
19 """Some custom function which is not required for the plugin to function."""
20 return random.randint(0, 100)
22 def add_report_context(self, report_instance, model_instance, request, context):
23 """Add example content to the report instance."""
24 # We can add any extra context data we want to the report
25 # Generate a random string of data
26 context['random_text'] = ''.join(
27 random.choices('abcdefghijklmnopqrstuvwxyz', k=20)
28 )
30 # Call a custom method
31 context['random_int'] = self.some_custom_function()
33 # We can also add extra data to the context which is specific to the report type
34 context['is_purchase_order'] = report_instance.model_type == 'purchaseorder'
36 # We can also use the 'request' object to add extra context data
37 context['request_method'] = request.method