mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-27 05:06:43 +00:00
Add report mixin page (#473)
* Add report mixin page * Add example * Add link from report page
This commit is contained in:
parent
26c4658de6
commit
7f0f94d923
@ -21,6 +21,7 @@ Consider the usecase for your plugin and define the exact function of the plugin
|
|||||||
|
|
||||||
- Is it just a simple REST-endpoint that runs a function ([ActionMixin](./plugins/action.md)) or a parser for a custom barcode format ([BarcodeMixin](./plugins/barcode.md))?
|
- Is it just a simple REST-endpoint that runs a function ([ActionMixin](./plugins/action.md)) or a parser for a custom barcode format ([BarcodeMixin](./plugins/barcode.md))?
|
||||||
- How does the user interact with the plugin? Is it a UI separate from the main InvenTree UI ([UrlsMixin](./plugins/urls.md)), does it need multiple pages with navigation-links ([NavigationMixin](./plugins/navigation.md)).
|
- How does the user interact with the plugin? Is it a UI separate from the main InvenTree UI ([UrlsMixin](./plugins/urls.md)), does it need multiple pages with navigation-links ([NavigationMixin](./plugins/navigation.md)).
|
||||||
|
- Do you need to extend reporting functionality? Check out the [ReportMixin](./plugins/report.md).
|
||||||
- Will it make calls to external APIs ([APICallMixin](./plugins/api.md) helps there)?
|
- Will it make calls to external APIs ([APICallMixin](./plugins/api.md) helps there)?
|
||||||
- Do you need to run in the background ([ScheduleMixin](./plugins/schedule.md)) or when things in InvenTree change ([EventMixin](./plugins/event.md))?
|
- Do you need to run in the background ([ScheduleMixin](./plugins/schedule.md)) or when things in InvenTree change ([EventMixin](./plugins/event.md))?
|
||||||
- Does the plugin need configuration that should be user changeable ([SettingsMixin](./plugins/settings.md)) or static (just use a yaml in the config dir)?
|
- Does the plugin need configuration that should be user changeable ([SettingsMixin](./plugins/settings.md)) or static (just use a yaml in the config dir)?
|
||||||
|
@ -98,6 +98,7 @@ Supported mixin classes are:
|
|||||||
- [LocateMixin](./plugins/locate.md)
|
- [LocateMixin](./plugins/locate.md)
|
||||||
- [NavigationMixin](./plugins/navigation.md)
|
- [NavigationMixin](./plugins/navigation.md)
|
||||||
- [PanelMixin](./plugins/panel.md)
|
- [PanelMixin](./plugins/panel.md)
|
||||||
|
- [ReportMixin](./plugins/report.md)
|
||||||
- [ScheduleMixin](./plugins/schedule.md)
|
- [ScheduleMixin](./plugins/schedule.md)
|
||||||
- [SettingsMixin](./plugins/settings.md)
|
- [SettingsMixin](./plugins/settings.md)
|
||||||
- [UrlsMixin](./plugins/urls.md)
|
- [UrlsMixin](./plugins/urls.md)
|
||||||
|
@ -157,6 +157,5 @@ Here are some examples of available colors:
|
|||||||
|
|
||||||
Please have a look at the css files for more options. The last line renders the value that was defined in the plugin.
|
Please have a look at the css files for more options. The last line renders the value that was defined in the plugin.
|
||||||
|
|
||||||
Just give it a try: Each time you press the button, the value will be increased.
|
!!! tip "Give it a try"
|
||||||
|
Each time you press the button, the value will be increased.
|
||||||
Have fun
|
|
||||||
|
52
docs/extend/plugins/report.md
Normal file
52
docs/extend/plugins/report.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
title: Report Mixin
|
||||||
|
---
|
||||||
|
|
||||||
|
## ReportMixin
|
||||||
|
|
||||||
|
The ReportMixin class provides a plugin with the ability to extend the functionality of custom [report templates](../../report/report.md). A plugin which implements the ReportMixin mixin class can add custom context data to a report template for rendering.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
A sample plugin which provides additional context data to the report templates can be found [in the InvenTree source code](https://github.com/inventree/InvenTree/blob/master/InvenTree/plugin/samples/integration/report_plugin_sample.py):
|
||||||
|
|
||||||
|
```python
|
||||||
|
"""Sample plugin for extending reporting functionality"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
from plugin import InvenTreePlugin
|
||||||
|
from plugin.mixins import ReportMixin
|
||||||
|
from report.models import PurchaseOrderReport
|
||||||
|
|
||||||
|
|
||||||
|
class SampleReportPlugin(ReportMixin, InvenTreePlugin):
|
||||||
|
"""Sample plugin which provides extra context data to a report"""
|
||||||
|
|
||||||
|
NAME = "Report Plugin"
|
||||||
|
SLUG = "reportexample"
|
||||||
|
TITLE = "Sample Report Plugin"
|
||||||
|
DESCRIPTION = "A sample plugin which provides extra context data to a report"
|
||||||
|
VERSION = "1.0"
|
||||||
|
|
||||||
|
def some_custom_function(self):
|
||||||
|
"""Some custom function which is not required for the plugin to function"""
|
||||||
|
return random.randint(0, 100)
|
||||||
|
|
||||||
|
def add_report_context(self, instance, request, context):
|
||||||
|
"""Add example content to the report instance"""
|
||||||
|
|
||||||
|
# We can add any extra context data we want to the report
|
||||||
|
|
||||||
|
# Generate a random string of data
|
||||||
|
context['random_text'] = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz', k=20))
|
||||||
|
|
||||||
|
# Call a custom method
|
||||||
|
context['random_int'] = self.some_custom_function()
|
||||||
|
|
||||||
|
# We can also add extra data to the context which is specific to the report type
|
||||||
|
context['is_purchase_order'] = isinstance(instance, PurchaseOrderReport)
|
||||||
|
|
||||||
|
# We can also use the 'request' object to add extra context data
|
||||||
|
context['request_method'] = request.method
|
||||||
|
```
|
@ -133,6 +133,9 @@ So, if you are writing a template which has custom formatting, (or any other sec
|
|||||||
!!! tip "Close it out"
|
!!! tip "Close it out"
|
||||||
Don't forget to end with a `{% raw %}{% endlocalize %}{% endraw %}` tag!
|
Don't forget to end with a `{% raw %}{% endlocalize %}{% endraw %}` tag!
|
||||||
|
|
||||||
|
### Extending with Plugins
|
||||||
|
|
||||||
|
The [ReportMixin plugin class](../extend/plugins/report.md) allows reporting functionality to be extended with custom features.
|
||||||
|
|
||||||
## Report Types
|
## Report Types
|
||||||
|
|
||||||
|
@ -179,6 +179,7 @@ nav:
|
|||||||
- Locate Mixin: extend/plugins/locate.md
|
- Locate Mixin: extend/plugins/locate.md
|
||||||
- Navigation Mixin: extend/plugins/navigation.md
|
- Navigation Mixin: extend/plugins/navigation.md
|
||||||
- Panel Mixin: extend/plugins/panel.md
|
- Panel Mixin: extend/plugins/panel.md
|
||||||
|
- Report Mixin: extend/plugins/report.md
|
||||||
- Schedule Mixin: extend/plugins/schedule.md
|
- Schedule Mixin: extend/plugins/schedule.md
|
||||||
- Settings Mixin: extend/plugins/settings.md
|
- Settings Mixin: extend/plugins/settings.md
|
||||||
- URL Mixin: extend/plugins/urls.md
|
- URL Mixin: extend/plugins/urls.md
|
||||||
|
Loading…
x
Reference in New Issue
Block a user