mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-13 10:35:40 +00:00
Report printing refactor (#7074)
* Adds a new "generic" ReportTemplate model * expose API endpoints * Update model / migrations / serializer * Add new mixin class to existing database models * - Add detail view for report template - Revert filters field behaviour * Filter report list by provided item IDs - Greatly simplify filtering logic compared to existing implemetation - Expose to API schema * Create data migration for converting *old* report templates * Ignore internal reports for data migration * Add report mixin to StockLocation model * Provide model choices in admin interface * Offload context data generation to the model classes * Remove old report template models * Refactor JS code in CUI * Fix for API filtering * Add data migration to delete old models * Remove dead URL * Updates * Construct sample report templates on app start * Bump API version * Typo fix * Fix incorrect context calls * Add new LabelTemplate model - ReportTemplate and LabelTemplate share common base - Refactor previous migration * Expose to admin interface * Add in extra context from existing label models * Add migration to create LabelTemplate instances from existing labels * Add API endpoints for listing and updating LabelTemplate objects * Adjust 'upload_to' path * Refactor label printing * Move default label templates * Update API endpoints * Update migrations * Handle LookupError in migration * Redirect the "label" API endpoint * Add new model for handling result of template printing * Refactor LabelPrinting mixin * Unlink "labels" app entirely * Fix typo * Record 'plugin' used to generate a particular output * Fix imports * Generate label print response - Still not good yet * Refactoring label printing in CUI * add "items" count to TemplateOutput model * Fix for InvenTreeLabelSheetPlugin * Remove old "label" app * Make request object optional * Fix filename generation * Add help text for "model_type" * Simplify TemplateTable * Tweak TemplateTable * Get template editor to display template data again * Stringify template name - Important, otherwise you get a TypeError instead of TemplateDoesNotExist * Add hooks to reset plugin state * fix context for StockLocation model * Tweak log messages * Fix incorrect serializer * Cleanup TemplateTable * Fix broken import * Filter by target model type * Remove manual file operations * Update old migrations - Remove references to functions that no longer exist * Refactor asset / snippet uploading * Update comments * Retain original filename when editing templatese * Cleanup * Refactor model type filter to use new hook * Add placeholder actions for printing labels and reports * Improve hookiness * Add new ReportOutput class * Report printing works from PUI now! * More inspired filename pattern for generated reports * Fix template preview window - Use new "output" response field across the board * Remove outdated task * Update data migration to use raw SQL - If the 'labels' app is no longer available, this will fail - So, use raw SQL instead * Add more API endpoint defs * Adds placeholder API endpoint for label printing * Expose plugin field to the printing endpoint * Adds plugin model type * Hook to print labels * Refactor action dropdown items * Refactor report printing for CUI * Refactor label print for CUI - Still needs to handle custom printing options for plugin * Fix migration * Update ModelType dict * playwright test fix * Unit test fixes * Fix model ruleset associations * Fix for report.js * Add support for "dynamic" fields in metadata.py * Add in custom fields based on plugin * Refactoring * Reset plugin on form close * Set custom timeout values * Update migration - Not atomic * Cleanup * Implement more printing actions * Reduce timeout * Unit test updates * Fix part serializers * Label printing works in CUI again * js linting * Update <ActionDropdown> * Fix for label printing API endpoint * Fix filterselectdrawer * Improve button rendering * Allow printing from StockLocationTable * Add aria-labels to modal form fields * Add test for printing stock item labels from table * Add test for report printing * Add unit testing for report template editing / preview * Message refactor * Refactor InvenTreeReportMixin class * Update playwright test * Update 'verbose_name' for a number of models * Additional admin filtering * Playwright test updates * Run checks against new python lib branch (temporary, will be reverted) * remove old app reference * fix testing ref * fix app init * remove old tests * Revert custom target branch * Expose label and report output objects to API * refactor * fix a few tests * factor plugin_ref out * fix options testing * Update table field header * re-enable full options testing * fix missing plugin matching * disable call assert * Add custom related field for PluginConfig - Uses 'key' rather than 'pk' - Revert label print plugin to use slug * Add support for custom pk field in metadata * switch to labels for testing * re-align report testing code * disable version check * fix url * Implement lazy loading * Allow blank plugin for printing - Uses the builtin label printer if not specified * Add printing actions for StockItem * Fix for metadata helper * Use key instead of pk in printing actions * Support non-standard pk values in RelatedModelField * pass context data to report serializers * disable template / item discovery * fix call * Tweak unit test * Run python checks against specific branch * Add task for running docs server - Option to compile schema as part of task * Custom branch no longer needed * Starting on documentation updates * fix tests for reports * fix label testing * Update template context variables * Refactor report context documentation * Documentation cleanup * Docs cleanup * Include sample report files * Fix links * Link cleanup * Integrate plugin example code into docs * Code cleanup * Fix type annotation * Revert deleted variable * remove templatetype * remove unused imports * extend context testing * test if plg can print * re-enable version check * Update unit tests * Fix test * Adjust unit test * Add debug statement to test * Fix unit test - Labels get printed against LabelTemplate items, duh * Unit test update * Unit test updates * Test update * Patch fix for <PartColumn> component * Fix ReportSerialierBase class - Re-initialize field options if not already set * Fix unit test for sqlite * Fix kwargs for non-blocking label printing * Update playwright tests * Tweak unit test --------- Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
BIN
docs/docs/assets/images/report/report_template_admin.png
Normal file
BIN
docs/docs/assets/images/report/report_template_admin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
@ -15,4 +15,14 @@ POST {
|
||||
}
|
||||
```
|
||||
|
||||
For an example of a very simple action plugin, refer to `/src/backend/InvenTree/plugin/samples/integratoni/simpleactionplugin.py`
|
||||
### Sample Plugin
|
||||
|
||||
A sample action plugin is provided in the `InvenTree` source code, which can be used as a template for creating custom action plugins:
|
||||
|
||||
::: plugin.samples.integration.simpleactionplugin.SimpleActionPlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
@ -5,3 +5,15 @@ title: Schedule Mixin
|
||||
## APICallMixin
|
||||
|
||||
The APICallMixin class provides basic functionality for integration with an external API.
|
||||
|
||||
### Sample Plugin
|
||||
|
||||
The following example demonstrates how to use the `APICallMixin` class to make a simple API call:
|
||||
|
||||
::: plugin.samples.integration.api_caller.SampleApiCallerPlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
@ -2,7 +2,7 @@
|
||||
title: Barcode Mixin
|
||||
---
|
||||
|
||||
### Barcode Plugins
|
||||
## Barcode Plugins
|
||||
|
||||
InvenTree supports decoding of arbitrary barcode data via a **Barcode Plugin** interface. Barcode data POSTed to the `/api/barcode/` endpoint will be supplied to all loaded barcode plugins, and the first plugin to successfully interpret the barcode data will return a response to the client.
|
||||
|
||||
@ -24,7 +24,21 @@ POST {
|
||||
}
|
||||
```
|
||||
|
||||
### Example
|
||||
### Builtin Plugin
|
||||
|
||||
The InvenTree server includes a builtin barcode plugin which can decode QR codes generated by the server. This plugin is enabled by default.
|
||||
|
||||
::: plugin.builtin.barcodes.inventree_barcode.InvenTreeInternalBarcodePlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
||||
|
||||
### Example Plugin
|
||||
|
||||
Please find below a very simple example that is executed each time a barcode is scanned.
|
||||
|
||||
```python
|
||||
|
@ -6,7 +6,24 @@ title: Currency Exchange Mixin
|
||||
|
||||
The `CurrencyExchangeMixin` class enabled plugins to provide custom backends for updating currency exchange rate information.
|
||||
|
||||
Any implementing classes must provide the `update_exchange_rates` method. A simple example is shown below (with fake data).
|
||||
Any implementing classes must provide the `update_exchange_rates` method.
|
||||
|
||||
### Builtin Plugin
|
||||
|
||||
The default builtin plugin for handling currency exchange rates is the `InvenTreeCurrencyExchangePlugin` class.
|
||||
|
||||
::: plugin.builtin.integration.currency_exchange.InvenTreeCurrencyExchange
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
||||
|
||||
### Sample Plugin
|
||||
|
||||
A simple example is shown below (with fake data).
|
||||
|
||||
```python
|
||||
|
||||
|
@ -15,56 +15,34 @@ When a certain (server-side) event occurs, the background worker passes the even
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Example (all events)
|
||||
### Sample Plugin - All events
|
||||
|
||||
Implementing classes must at least provide a `process_event` function:
|
||||
|
||||
```python
|
||||
class EventPlugin(EventMixin, InvenTreePlugin):
|
||||
"""
|
||||
A simple example plugin which responds to events on the InvenTree server.
|
||||
::: plugin.samples.event.event_sample.EventPluginSample
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
||||
This example simply prints out the event information.
|
||||
A more complex plugin could respond to specific events however it wanted.
|
||||
"""
|
||||
|
||||
NAME = "EventPlugin"
|
||||
SLUG = "event"
|
||||
TITLE = "Triggered Events"
|
||||
|
||||
def process_event(self, event, *args, **kwargs):
|
||||
print(f"Processing triggered event: '{event}'")
|
||||
```
|
||||
|
||||
### Example (specific events)
|
||||
### Sample Plugin - Specific Events
|
||||
|
||||
If you want to process just some specific events, you can also implement the `wants_process_event` function to decide if you want to process this event or not. This function will be executed synchronously, so be aware that it should contain simple logic.
|
||||
|
||||
Overall this function can reduce the workload on the background workers significantly since less events are queued to be processed.
|
||||
|
||||
```python
|
||||
class EventPlugin(EventMixin, InvenTreePlugin):
|
||||
"""
|
||||
A simple example plugin which responds to 'salesordershipment.completed' event on the InvenTree server.
|
||||
::: plugin.samples.event.filtered_event_sample.FilteredEventPluginSample
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
||||
This example simply prints out the event information.
|
||||
A more complex plugin can run enhanced logic on this event.
|
||||
"""
|
||||
|
||||
NAME = "EventPlugin"
|
||||
SLUG = "event"
|
||||
TITLE = "Triggered Events"
|
||||
|
||||
def wants_process_event(self, event):
|
||||
"""Here you can decide if this event should be send to `process_event` or not."""
|
||||
return event == "salesordershipment.completed"
|
||||
|
||||
def process_event(self, event, *args, **kwargs):
|
||||
"""Here you can run you'r specific logic."""
|
||||
print(f"Sales order was completely shipped: '{args}' '{kwargs}'")
|
||||
```
|
||||
|
||||
### Events
|
||||
## Events
|
||||
|
||||
Events are passed through using a string identifier, e.g. `build.completed`
|
||||
|
||||
|
@ -172,6 +172,14 @@ InvenTree supplies the `InvenTreeLabelPlugin` out of the box, which generates a
|
||||
|
||||
The default plugin also features a *DEBUG* mode which generates a raw HTML output, rather than PDF. This can be handy for tracking down any template rendering errors in your labels.
|
||||
|
||||
::: plugin.builtin.labels.inventree_label.InvenTreeLabelPlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
||||
### Available Data
|
||||
|
||||
The *label* data are supplied to the plugin in both `PDF` and `PNG` formats. This provides compatibility with a great range of label printers "out of the box". Conversion to other formats, if required, is left as an exercise for the plugin developer.
|
||||
|
@ -29,3 +29,15 @@ If a locate plugin is installed and activated, the [InvenTree mobile app](../../
|
||||
### Implementation
|
||||
|
||||
Refer to the [InvenTree source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/locate/locate_sample.py) for a simple implementation example.
|
||||
|
||||
### Sample Plugin
|
||||
|
||||
A simple example is provided in the InvenTree code base:
|
||||
|
||||
::: plugin.samples.locate.locate_sample.SampleLocatePlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
@ -52,6 +52,18 @@ Or to add a template file that will be rendered as javascript code, from the plu
|
||||
|
||||
Note : see convention for template directory above.
|
||||
|
||||
## Sample Plugin
|
||||
|
||||
A sample plugin is provided in the InvenTree code base:
|
||||
|
||||
::: plugin.samples.integration.custom_panel_sample.CustomPanelSample
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
||||
## Example Implementations
|
||||
|
||||
Refer to the `CustomPanelSample` example class in the `./plugin/samples/integration/` directory, for a fully worked example of how custom UI panels can be implemented.
|
||||
|
@ -14,48 +14,14 @@ A plugin which implements the ReportMixin mixin can define the `add_report_conte
|
||||
|
||||
Additionally the `add_label_context` method, allowing custom context data to be added to a label template at time of printing.
|
||||
|
||||
### Example
|
||||
### Sample Plugin
|
||||
|
||||
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/src/backend/InvenTree/plugin/samples/integration/report_plugin_sample.py):
|
||||
A sample plugin which provides additional context data to the report templates is available:
|
||||
|
||||
```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 = "Sample 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, report_instance, model_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(report_instance, PurchaseOrderReport)
|
||||
|
||||
# We can also use the 'request' object to add extra context data
|
||||
context['request_method'] = request.method
|
||||
```
|
||||
::: plugin.samples.integration.report_plugin_sample.SampleReportPlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
@ -18,45 +18,14 @@ The ScheduleMixin class provides a plugin with the ability to call functions at
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Example
|
||||
### SamplePlugin
|
||||
|
||||
An example of a plugin which supports scheduled tasks:
|
||||
|
||||
```python
|
||||
class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin):
|
||||
"""
|
||||
Sample plugin which runs a scheduled task, and provides user configuration.
|
||||
"""
|
||||
|
||||
NAME = "Scheduled Tasks"
|
||||
SLUG = 'schedule'
|
||||
|
||||
SCHEDULED_TASKS = {
|
||||
'global': {
|
||||
'func': 'some_module.function',
|
||||
'schedule': 'H', # Run every hour
|
||||
},
|
||||
'member': {
|
||||
'func': 'foo',
|
||||
'schedule': 'I', # Minutes
|
||||
'minutes': 15,
|
||||
},
|
||||
}
|
||||
|
||||
SETTINGS = {
|
||||
'SECRET': {
|
||||
'name': 'A secret',
|
||||
'description': 'User configurable value',
|
||||
},
|
||||
}
|
||||
|
||||
def foo(self):
|
||||
"""
|
||||
This function runs every 15 minutes
|
||||
"""
|
||||
secret_value = self.get_setting('SECRET')
|
||||
print(f"foo - SECRET = {secret_value})
|
||||
```
|
||||
|
||||
!!! info "More Info"
|
||||
For more information on any of the methods described below, refer to the InvenTree source code. [A working example is available as a starting point](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/scheduled_task.py).
|
||||
::: plugin.samples.integration.scheduled_task.ScheduledTaskPlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
@ -15,7 +15,7 @@ The dict must be formatted similar to the following sample that shows how to use
|
||||
|
||||
Take a look at the settings defined in `InvenTree.common.models.InvenTreeSetting` for all possible parameters.
|
||||
|
||||
### Example
|
||||
### Example Plugin
|
||||
|
||||
Below is a simple example of how a plugin can implement settings:
|
||||
|
||||
|
@ -58,7 +58,7 @@ To indicate a *field* validation error (i.e. the validation error applies only t
|
||||
|
||||
Note that an error can be which corresponds to multiple model instance fields.
|
||||
|
||||
### Example
|
||||
### Example Plugin
|
||||
|
||||
Presented below is a simple working example for a plugin which implements the `validate_model_instance` method:
|
||||
|
||||
@ -188,3 +188,15 @@ def increment_serial_number(self, serial: str):
|
||||
|
||||
return val
|
||||
```
|
||||
|
||||
## Sample Plugin
|
||||
|
||||
A sample plugin which implements custom validation routines is provided in the InvenTree source code:
|
||||
|
||||
::: plugin.samples.integration.validation_sample.SampleValidatorPlugin
|
||||
options:
|
||||
show_bases: False
|
||||
show_root_heading: False
|
||||
show_root_toc_entry: False
|
||||
show_source: True
|
||||
members: []
|
||||
|
@ -14,7 +14,7 @@ Navigate to the "Settings" page and click on the "Display" tab, you should see t
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
The drop-down list let's you select any other color theme found in your static folder (see next section to find out how to [add color themes](#add-color-themes)). Once selected, click on the "Apply Theme" button for the new color theme to be activated.
|
||||
The drop-down list let's you select any other color theme found in your static folder (see next section to find out how to [add color themes](#add-color-theme)). Once selected, click on the "Apply Theme" button for the new color theme to be activated.
|
||||
|
||||
!!! info "Per-user Setting"
|
||||
Color themes are "user specific" which means that changing the color theme in your own settings won't affect other users.
|
||||
|
@ -98,7 +98,7 @@ While [line items](#line-items) must reference a particular stock item, extra li
|
||||
|
||||
## Return Order Reports
|
||||
|
||||
Custom [reports](../report/return_order.md) can be generated against each Return Order.
|
||||
Custom [reports](../report/templates.md) can be generated against each Return Order.
|
||||
|
||||
### Calendar view
|
||||
|
||||
|
@ -24,7 +24,7 @@ Refer to the [report documentation](../report/report.md) for further information
|
||||
!!! warning "LaTeX Support"
|
||||
LaTeX report templates are no longer supported for a number of technical and ideological reasons
|
||||
|
||||
[#1292](https://github.com/inventree/InvenTree/pull/1292) adds support for build order / work order reports. Refer to the [build report documentation](../report/build.md) for further information.
|
||||
[#1292](https://github.com/inventree/InvenTree/pull/1292) adds support for build order / work order reports. Refer to the [report documentation](../report/templates.md) for further information.
|
||||
|
||||
### Inherited BOM Items
|
||||
|
||||
|
@ -32,7 +32,7 @@ Details on how to create and manage manufacturer parts were added
|
||||
|
||||
[#1462](https://github.com/inventree/InvenTree/pull/1417) adds the ability to
|
||||
create a QR code containing the URL of a StockItem, which can be opened directly
|
||||
on a portable device using the camera or a QR code scanner. More details [here](../report/labels.md#url-style-qr-code).
|
||||
on a portable device using the camera or a QR code scanner. More details [here](../report/labels.md).
|
||||
|
||||
## Major Bug Fixes
|
||||
|
||||
|
@ -53,7 +53,7 @@ This release also provides a marked improvement in unit testing and code coverag
|
||||
[#2372](https://github.com/inventree/InvenTree/pull/2372) provides an overhaul of notifications, allowing users to view their notifications directly in the InvenTree interface.
|
||||
|
||||
### Why are you hiding my name?
|
||||
[#2861](https://github.com/inventree/InvenTree/pull/2861) adds several changes to enable admins to remove more of InvenTrees branding. Change logo, hide the about-modal for all but superusers and add custom messages to login and main navbar. Check out [the docs](../start/config.md#customisation-options).
|
||||
[#2861](https://github.com/inventree/InvenTree/pull/2861) adds several changes to enable admins to remove more of InvenTrees branding. Change logo, hide the about-modal for all but superusers and add custom messages to login and main navbar. Check out [the docs](../start/config.md#customization-options)
|
||||
|
||||
### Label Printing Plugin
|
||||
|
||||
|
@ -1,186 +0,0 @@
|
||||
---
|
||||
title: BOM Generation
|
||||
---
|
||||
|
||||
## BOM Generation
|
||||
|
||||
The bill of materials is an essential part of the documentation that needs to be sent to the factory. A simple csv export is OK to be important into SMT machines. But for human readable documentation it might not be sufficient. Additional information is needed. The Inventree report system allows to generate BOM well formatted BOM reports.
|
||||
|
||||
### Context variables
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| bom_items | Query set that contains all BOM items |
|
||||
| bom_items...sub_part | One component of the BOM |
|
||||
| bom_items...quantity | Number of parts |
|
||||
| bom_items...reference | Reference designators of the part |
|
||||
| bom_items...substitutes | Query set that contains substitutes of the part if any exist in the BOM |
|
||||
|
||||
### Examples
|
||||
|
||||
#### BOM
|
||||
|
||||
The following picture shows a simple example for a PCB with just three components from two different parts.
|
||||
|
||||
{% with id="report-options", url="report/bom_example.png", description="BOM example" %} {% include 'img.html' %} {% endwith %}
|
||||
|
||||
This example has been created using the following html template:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% extends "report/inventree_report_base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load report %}
|
||||
{% load inventree_extras %}
|
||||
|
||||
{% block page_margin %}
|
||||
margin-left: 2cm;
|
||||
margin-right: 1cm;
|
||||
margin-top: 4cm;
|
||||
{% endblock %}
|
||||
|
||||
{% block bottom_left %}
|
||||
content: "v{{report_revision}} - {% format_date date %}";
|
||||
{% endblock %}
|
||||
|
||||
{% block bottom_center %}
|
||||
content: "InvenTree v{% inventree_version %}";
|
||||
{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
.header-left {
|
||||
text-align: left;
|
||||
float: left;
|
||||
}
|
||||
table {
|
||||
border: 1px solid #eee;
|
||||
border-radius: 3px;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
font-size: 80%;
|
||||
}
|
||||
table td {
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block header_content %}
|
||||
<div class='header-left'>
|
||||
<h3>{% trans "Bill of Materials" %}</h3>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
<table>
|
||||
<tr> <td>Board</td><td>{{ part.IPN }}</td> </tr>
|
||||
<tr> <td>Description</td><td>{{ part.description }}</td> </tr>
|
||||
<tr> <td>User</td><td>{{ user }}</td> </tr>
|
||||
<tr> <td>Date</td><td>{{ date }}</td> </tr>
|
||||
<tr> <td>Number of different components (codes)</td><td>{{ bom_items.count }}</td> </tr>
|
||||
</table>
|
||||
<br>
|
||||
<table class='table table-striped table-condensed'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "IPN" %}</th>
|
||||
<th>{% trans "MPN" %}</th>
|
||||
<th>{% trans "Manufacturer" %}</th>
|
||||
<th>{% trans "Quantity" %}</th>
|
||||
<th>{% trans "Reference" %}</th>
|
||||
<th>{% trans "Substitute" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for line in bom_items.all %}
|
||||
<tr>
|
||||
<td>{{ line.sub_part.IPN }}</td>
|
||||
<td>{{ line.sub_part.name }}</td>
|
||||
<td>
|
||||
{% for manf in line.sub_part.manufacturer_parts.all %}
|
||||
{{ manf.manufacturer.name }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>{% decimal line.quantity %}</td>
|
||||
<td>{{ line.reference }}</td>
|
||||
<td>
|
||||
{% for sub in line.substitutes.all %}
|
||||
{{ sub.part.IPN }}<br>
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
#### Pick List
|
||||
|
||||
When all material has been allocated someone has to pick all things from the warehouse.
|
||||
In case you need a printed pick list you can use the following template. This it just the
|
||||
table. All other info and CSS has been left out for simplicity. Please have a look at the
|
||||
BOM report for details.
|
||||
|
||||
{% raw %}
|
||||
```html
|
||||
<table class='changes-table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Original IPN</th>
|
||||
<th>Allocated Part</th>
|
||||
<th>Location</th>
|
||||
<th>PCS</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for line in build.allocated_stock.all %}
|
||||
<tr>
|
||||
<td> {{ line.bom_item.sub_part.IPN }} </td>
|
||||
{% if line.stock_item.part.IPN != line.bom_item.sub_part.IPN %}
|
||||
<td class='chg'> {{ line.stock_item.part.IPN }} </td>
|
||||
{% else %}
|
||||
<td> {{ line.stock_item.part.IPN }} </td>
|
||||
{% endif %}
|
||||
<td> {{ line.stock_item.location.pathstring }} </td>
|
||||
<td> {{ line.quantity }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
Here we have a loop that runs through all allocated parts for the build. For each part
|
||||
we list the original IPN from the BOM and the IPN of the allocated part. These can differ
|
||||
in case you have substitutes or template/variants in the BOM. In case the parts differ
|
||||
we use a different format for the table cell e.g. print bold font or red color.
|
||||
For the picker we list the full path names of the stock locations and the quantity
|
||||
that is needed for the build. This will result in the following printout:
|
||||
|
||||
{% with id="picklist", url="report/picklist.png", description="Picklist Example" %} {% include "img.html" %} {% endwith %}
|
||||
|
||||
For those of you who would like to replace the "/" by something else because it is hard
|
||||
to read in some fonts use the following trick:
|
||||
|
||||
{% raw %}
|
||||
```html
|
||||
<td> {% for loc in line.stock_item.location.path %}{{ loc.name }}{% if not forloop.last %}-{% endif %}{% endfor %} </td>
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
Here we use location.path which is a query set that contains the location path up to the
|
||||
topmost parent. We use a loop to cycle through that and print the .name of the entry followed
|
||||
by a "-". The foorloop.last is a Django trick that allows us to not print the "-" after
|
||||
the last entry. The result looks like here:
|
||||
|
||||
{% with id="picklist_with_path", url="report/picklist_with_path.png", description="Picklist Example" %} {% include "img.html" %} {% endwith %}
|
||||
|
||||
Finally added a `{% raw %}|floatformat:0{% endraw %}` to the quantity that removes the trailing zeros.
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default *BOM Report* template is provided out of the box, which is useful for generating simple test reports. Furthermore, it may be used as a starting point for developing custom BOM reports:
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_bill_of_materials_report.html) for the default test report template.
|
@ -1,324 +0,0 @@
|
||||
---
|
||||
title: Build Order Report
|
||||
---
|
||||
|
||||
## Build Order Report
|
||||
|
||||
Custom build order reports may be generated against any given [Build Order](../build/build.md). For example, build order reports can be used to generate work orders.
|
||||
|
||||
### Build Filters
|
||||
|
||||
A build order report template may define a set of filters against which [Build Order](../build/build.md) items are sorted.
|
||||
|
||||
### Context Variables
|
||||
|
||||
In addition to the default report context variables, the following context variables are made available to the build order report template for rendering:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| build | The build object the report is being generated against |
|
||||
| part | The [Part](./context_variables.md#part) object that the build references |
|
||||
| line_items | A shortcut for [build.line_items](#build) |
|
||||
| bom_items | A shortcut for [build.bom_items](#build) |
|
||||
| build_outputs | A shortcut for [build.build_outputs](#build) |
|
||||
| reference | The build order reference string |
|
||||
| quantity | Build order quantity (number of assemblies being built) |
|
||||
|
||||
#### build
|
||||
|
||||
The following variables are accessed by build.variable
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| active | Boolean that tells if the build is active |
|
||||
| batch | Batch code transferred to build parts (optional) |
|
||||
| line_items | A query set with all the build line items associated with the build |
|
||||
| bom_items | A query set with all BOM items for the part being assembled |
|
||||
| build_outputs | A queryset containing all build output ([Stock Item](../stock/stock.md)) objects associated with this build |
|
||||
| can_complete | Boolean that tells if the build can be completed. Means: All material allocated and all parts have been build. |
|
||||
| are_untracked_parts_allocated | Boolean that tells if all bom_items have allocated stock_items. |
|
||||
| creation_date | Date where the build has been created |
|
||||
| completion_date | Date the build was completed (or, if incomplete, the expected date of completion) |
|
||||
| completed_by | The [User](./context_variables.md#user) that completed the build |
|
||||
| is_overdue | Boolean that tells if the build is overdue |
|
||||
| is_complete | Boolean that tells if the build is complete |
|
||||
| issued_by | The [User](./context_variables.md#user) who created the build |
|
||||
| link | External URL for extra information |
|
||||
| notes | Text notes |
|
||||
| parent | Reference to a parent build object if this is a sub build |
|
||||
| part | The [Part](./context_variables.md#part) to be built (from component BOM items) |
|
||||
| quantity | Build order quantity (total number of assembly outputs) |
|
||||
| completed | The number out outputs which have been completed |
|
||||
| reference | Build order reference (required, must be unique) |
|
||||
| required_parts | A query set with all parts that are required for the build |
|
||||
| responsible | Owner responsible for completing the build. This can be a user or a group. Depending on that further context variables differ |
|
||||
| sales_order | References to a [Sales Order](./context_variables.md#salesorder) object for which this build is required (e.g. the output of this build will be used to fulfil a sales order) |
|
||||
| status | The status of the build. 20 means 'Production' |
|
||||
| sub_build_count | Number of sub builds |
|
||||
| sub_builds | Query set with all sub builds |
|
||||
| target_date | Date the build will be overdue |
|
||||
| take_from | [StockLocation](./context_variables.md#stocklocation) to take stock from to make this build (if blank, can take from anywhere) |
|
||||
| title | The full name of the build |
|
||||
| description | The description of the build |
|
||||
| allocated_stock.all | A query set with all allocated stock items for the build |
|
||||
|
||||
As usual items in a query sets can be selected by adding a .n to the set e.g. build.required_parts.0
|
||||
will result in the first part of the list. Each query set has again its own context variables.
|
||||
|
||||
#### line_items
|
||||
|
||||
The `line_items` variable is a list of all build line items associated with the selected build. The following attributes are available for each individual line_item instance:
|
||||
|
||||
| Attribute | Description |
|
||||
| --- | --- |
|
||||
| .build | A reference back to the parent build order |
|
||||
| .bom_item | A reference to the BOMItem which defines this line item |
|
||||
| .quantity | The required quantity which is to be allocated against this line item |
|
||||
| .part | A shortcut for .bom_item.sub_part |
|
||||
| .allocations | A list of BuildItem objects which allocate stock items against this line item |
|
||||
| .allocated_quantity | The total stock quantity which has been allocated against this line |
|
||||
| .unallocated_quantity | The remaining quantity to allocate |
|
||||
| .is_fully_allocated | Boolean value, returns True if the line item has sufficient stock allocated against it |
|
||||
| .is_overallocated | Boolean value, returns True if the line item has more allocated stock than is required |
|
||||
|
||||
#### bom_items
|
||||
|
||||
| Attribute | Description |
|
||||
| --- | --- |
|
||||
| .reference | The reference designators of the components |
|
||||
| .quantity | The number of components required to build |
|
||||
| .overage | The extra amount required to assembly |
|
||||
| .consumable | Boolean field, True if this is a "consumable" part which is not tracked through builds |
|
||||
| .sub_part | The part at this position |
|
||||
| .substitutes.all | A query set with all allowed substitutes for that part |
|
||||
| .note | Extra text field which can contain additional information |
|
||||
|
||||
|
||||
#### allocated_stock.all
|
||||
|
||||
| Attribute | Description |
|
||||
| --- | --- |
|
||||
| .bom_item | The bom item where this part belongs to |
|
||||
| .stock_item | The allocated [StockItem](./context_variables.md#stockitem) |
|
||||
| .quantity | The number of components needed for the build (components in BOM x parts to build) |
|
||||
|
||||
### Example
|
||||
|
||||
The following example will create a report with header and BOM. In the BOM table substitutes will be listed.
|
||||
|
||||
{% raw %}
|
||||
```html
|
||||
{% extends "report/inventree_report_base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load report %}
|
||||
{% load barcode %}
|
||||
{% load inventree_extras %}
|
||||
{% load markdownify %}
|
||||
|
||||
{% block page_margin %}
|
||||
margin: 2cm;
|
||||
margin-top: 4cm;
|
||||
{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
|
||||
.header-right {
|
||||
text-align: right;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 20mm;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.details {
|
||||
width: 100%;
|
||||
border: 1px solid;
|
||||
border-radius: 3px;
|
||||
padding: 5px;
|
||||
min-height: 42mm;
|
||||
}
|
||||
|
||||
.details table {
|
||||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
width: 65%;
|
||||
table-layout: fixed;
|
||||
font-size: 75%;
|
||||
}
|
||||
.changes table {
|
||||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
width: 100%;
|
||||
table-layout: fixed;
|
||||
font-size: 75%;
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
.changes-table th {
|
||||
font-size: 100%;
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
.changes-table td {
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
.details table td:not(:last-child){
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.details table td:last-child{
|
||||
width: 50%;
|
||||
padding-left: 1cm;
|
||||
padding-right: 1cm;
|
||||
}
|
||||
|
||||
.details-table td {
|
||||
padding-left: 10px;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
border-bottom: 1px solid #555;
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block bottom_left %}
|
||||
content: "v{{report_revision}} - {% format_date date %}";
|
||||
{% endblock %}
|
||||
|
||||
{% block header_content %}
|
||||
<!-- TODO - Make the company logo asset generic -->
|
||||
<img class='logo' src="{% asset 'company_logo.png' %}" alt="logo" width="150">
|
||||
|
||||
<div class='header-right'>
|
||||
<h3>
|
||||
Build Order {{ build }}
|
||||
</h3>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
|
||||
<div class='details'>
|
||||
|
||||
<table class='details-table'>
|
||||
<tr>
|
||||
<th>{% trans "Build Order" %}</th>
|
||||
<td>{% internal_link build.get_absolute_url build %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Order" %}</th>
|
||||
<td>{{ reference }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Part" %}</th>
|
||||
<td>{% internal_link part.get_absolute_url part.IPN %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Quantity" %}</th>
|
||||
<td>{{ build.quantity }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Description" %}</th>
|
||||
<td>{{ build.title }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Issued" %}</th>
|
||||
<td>{% format_date build.creation_date %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Target Date" %}</th>
|
||||
<td>
|
||||
{% if build.target_date %}
|
||||
{% format_date build.target_date %}
|
||||
{% else %}
|
||||
<em>Not specified</em>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% if build.parent %}
|
||||
<tr>
|
||||
<th>{% trans "Required For" %}</th>
|
||||
<td>{% internal_link build.parent.get_absolute_url build.parent %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if build.issued_by %}
|
||||
<tr>
|
||||
<th>{% trans "Issued By" %}</th>
|
||||
<td>{{ build.issued_by }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if build.responsible %}
|
||||
<tr>
|
||||
<th>{% trans "Responsible" %}</th>
|
||||
<td>{{ build.responsible }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th>{% trans "Sub builds count" %}</th>
|
||||
<td>{{ build.sub_build_count }}</td>
|
||||
</tr>
|
||||
{% if build.sub_build_count > 0 %}
|
||||
<tr>
|
||||
<th>{% trans "Sub Builds" %}</th>
|
||||
<td>{{ build.sub_builds }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th>{% trans "Overdue" %}</th>
|
||||
<td>{{ build.is_overdue }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Can complete" %}</th>
|
||||
<td>{{ build.can_complete }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h3>{% trans "Notes" %}</h3>
|
||||
{% if build.notes %}
|
||||
{{ build.notes|markdownify }}
|
||||
{% endif %}
|
||||
|
||||
<h3>{% trans "Parts" %}</h3>
|
||||
|
||||
<div class='changes'>
|
||||
<table class='changes-table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Original IPN</th>
|
||||
<th>Reference</th>
|
||||
<th>Replace width IPN</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for line in build.bom_items %}
|
||||
<tr>
|
||||
<td> {{ line.sub_part.IPN }} </td>
|
||||
<td> {{ line.reference }} </td>
|
||||
<td> {{ line.substitutes.all.0.part.IPN }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
|
||||
This will result a report page like this:
|
||||
|
||||
{% with id="report-options", url="build/report-61.png", description="Report Example Builds" %} {% include "img.html" %} {% endwith %}
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default *Build Report* template is provided out of the box, which is useful for generating simple test reports. Furthermore, it may be used as a starting point for developing custom BOM reports:
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_build_order_base.html) for the default build report template.
|
@ -2,64 +2,245 @@
|
||||
title: Context Variables
|
||||
---
|
||||
|
||||
|
||||
## Context Variables
|
||||
|
||||
### Report
|
||||
Context variables are provided to each template when it is rendered. The available context variables depend on the model type for which the template is being rendered.
|
||||
|
||||
!!! info "Specific Report Context"
|
||||
Specific report types may have additional context variables, see below.
|
||||
### Global Context
|
||||
|
||||
Each report has access to a number of context variables by default. The following context variables are provided to every report template:
|
||||
In addition to the model-specific context variables, the following global context variables are available to all templates:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| base_url | The base URL for the InvenTree instance |
|
||||
| date | Current date, represented as a Python datetime.date object |
|
||||
| datetime | Current datetime, represented as a Python datetime object |
|
||||
| page_size | The specified page size for this report, e.g. `A4` or `Letter landscape` |
|
||||
| report_template | The report template model instance |
|
||||
| report_name | Name of the report template |
|
||||
| report_description | Description of the report template |
|
||||
| report_revision | Revision of the report template |
|
||||
| request | Django request object |
|
||||
| request | The Django request object associated with the printing process |
|
||||
| template | The report template instance which is being rendered against |
|
||||
| template_description | Description of the report template |
|
||||
| template_name | Name of the report template |
|
||||
| template_revision | Revision of the report template |
|
||||
| user | User who made the request to render the template |
|
||||
|
||||
#### Label
|
||||
::: report.models.ReportTemplateBase.base_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
Certain types of labels have different context variables then other labels.
|
||||
### Report Context
|
||||
|
||||
##### Stock Item Label
|
||||
|
||||
The following variables are made available to the StockItem label template:
|
||||
In addition to the [global context](#global-context), all *report* templates have access to the following context variables:
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| item | The [StockItem](./context_variables.md#stockitem) object itself |
|
||||
| part | The [Part](./context_variables.md#part) object which is referenced by the [StockItem](./context_variables.md#stockitem) object |
|
||||
| name | The `name` field of the associated Part object |
|
||||
| ipn | The `IPN` field of the associated Part object |
|
||||
| revision | The `revision` field of the associated Part object |
|
||||
| quantity | The `quantity` field of the StockItem object |
|
||||
| serial | The `serial` field of the StockItem object |
|
||||
| uid | The `uid` field of the StockItem object |
|
||||
| tests | Dict object of TestResult data associated with the StockItem |
|
||||
| --- | --- |
|
||||
| page_size | The page size of the report |
|
||||
| landscape | Boolean value, True if the report is in landscape mode |
|
||||
|
||||
Note that custom plugins may also add additional context variables to the report context.
|
||||
|
||||
::: report.models.ReportTemplate.get_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
### Label Context
|
||||
|
||||
In addition to the [global context](#global-context), all *label* templates have access to the following context variables:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| width | The width of the label (in mm) |
|
||||
| height | The height of the label (in mm) |
|
||||
|
||||
Note that custom plugins may also add additional context variables to the label context.
|
||||
|
||||
::: report.models.LabelTemplate.get_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
|
||||
## Template Types
|
||||
|
||||
Templates (whether for generating [reports](./report.md) or [labels](./labels.md)) are rendered against a particular "model" type. The following model types are supported, and can have templates renderer against them:
|
||||
|
||||
| Model Type | Description |
|
||||
| --- | --- |
|
||||
| [build](#build-order) | A [Build Order](../build/build.md) instance |
|
||||
| [buildline](#build-line) | A [Build Order Line Item](../build/build.md) instance |
|
||||
| [salesorder](#sales-order) | A [Sales Order](../order/sales_order.md) instance |
|
||||
| [returnorder](#return-order) | A [Return Order](../order/return_order.md) instance |
|
||||
| [purchaseorder](#purchase-order) | A [Purchase Order](../order/purchase_order.md) instance |
|
||||
| [stockitem](#stock-item) | A [StockItem](../stock/stock.md#stock-item) instance |
|
||||
| [stocklocation](#stock-location) | A [StockLocation](../stock/stock.md#stock-location) instance |
|
||||
| [part](#part) | A [Part](../part/part.md) instance |
|
||||
|
||||
### Build Order
|
||||
|
||||
When printing a report or label against a [Build Order](../build/build.md) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| bom_items | Query set of all BuildItem objects associated with the BuildOrder |
|
||||
| build | The BuildOrder instance itself |
|
||||
| build_outputs | Query set of all BuildItem objects associated with the BuildOrder |
|
||||
| line_items | Query set of all build line items associated with the BuildOrder |
|
||||
| part | The Part object which is being assembled in the build order |
|
||||
| quantity | The total quantity of the part being assembled |
|
||||
| reference | The reference field of the BuildOrder |
|
||||
| title | The title field of the BuildOrder |
|
||||
|
||||
::: build.models.Build.report_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
### Build Line
|
||||
|
||||
When printing a report or label against a [BuildOrderLineItem](../build/build.md) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| allocated_quantity | The quantity of the part which has been allocated to this build |
|
||||
| allocations | A query set of all StockItem objects which have been allocated to this build line |
|
||||
| bom_item | The BomItem associated with this line item |
|
||||
| build | The BuildOrder instance associated with this line item |
|
||||
| build_line | The build line instance itself |
|
||||
| part | The sub-part (component) associated with the linked BomItem instance |
|
||||
| quantity | The quantity required for this line item |
|
||||
|
||||
::: build.models.BuildLine.report_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
|
||||
### Sales Order
|
||||
|
||||
When printing a report or label against a [SalesOrder](../order/sales_order.md) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| customer | The customer object associated with the SalesOrder |
|
||||
| description | The description field of the SalesOrder |
|
||||
| extra_lines | Query set of all extra lines associated with the SalesOrder |
|
||||
| lines | Query set of all line items associated with the SalesOrder |
|
||||
| order | The SalesOrder instance itself |
|
||||
| reference | The reference field of the SalesOrder |
|
||||
| title | The title (string representation) of the SalesOrder |
|
||||
|
||||
::: order.models.Order.report_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
### Return Order
|
||||
|
||||
When printing a report or label against a [ReturnOrder](../order/return_order.md) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| customer | The customer object associated with the ReturnOrder |
|
||||
| description | The description field of the ReturnOrder |
|
||||
| extra_lines | Query set of all extra lines associated with the ReturnOrder |
|
||||
| lines | Query set of all line items associated with the ReturnOrder |
|
||||
| order | The ReturnOrder instance itself |
|
||||
| reference | The reference field of the ReturnOrder |
|
||||
| title | The title (string representation) of the ReturnOrder |
|
||||
|
||||
### Purchase Order
|
||||
|
||||
When printing a report or label against a [PurchaseOrder](../order/purchase_order.md) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| description | The description field of the PurchaseOrder |
|
||||
| extra_lines | Query set of all extra lines associated with the PurchaseOrder |
|
||||
| lines | Query set of all line items associated with the PurchaseOrder |
|
||||
| order | The PurchaseOrder instance itself |
|
||||
| reference | The reference field of the PurchaseOrder |
|
||||
| supplier | The supplier object associated with the PurchaseOrder |
|
||||
| title | The title (string representation) of the PurchaseOrder |
|
||||
|
||||
### Stock Item
|
||||
|
||||
When printing a report or label against a [StockItem](../stock/stock.md#stock-item) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| barcode_data | Generated barcode data for the StockItem |
|
||||
| barcode_hash | Hash of the barcode data |
|
||||
| batch | The batch code for the StockItem |
|
||||
| child_items | Query set of all StockItem objects which are children of this StockItem |
|
||||
| ipn | The IPN (internal part number) of the associated Part |
|
||||
| installed_items | Query set of all StockItem objects which are installed in this StockItem |
|
||||
| item | The StockItem object itself |
|
||||
| name | The name of the associated Part |
|
||||
| part | The Part object which is associated with the StockItem |
|
||||
| qr_data | Generated QR code data for the StockItem |
|
||||
| qr_url | Generated URL for embedding in a QR code |
|
||||
| parameters | Dict object containing the parameters associated with the base Part |
|
||||
| quantity | The quantity of the StockItem |
|
||||
| result_list | FLattened list of TestResult data associated with the stock item |
|
||||
| results | Dict object of TestResult data associated with the StockItem |
|
||||
| serial | The serial number of the StockItem |
|
||||
| stock_item | The StockItem object itself (shadow of 'item') |
|
||||
| tests | Dict object of TestResult data associated with the StockItem (shadow of 'results') |
|
||||
| test_keys | List of test keys associated with the StockItem |
|
||||
| test_template_list | List of test templates associated with the StockItem |
|
||||
| test_templates | Dict object of test templates associated with the StockItem |
|
||||
|
||||
::: stock.models.StockItem.report_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
|
||||
##### Stock Location Label
|
||||
### Stock Location
|
||||
|
||||
The following variables are made available to the StockLocation label template:
|
||||
When printing a report or label against a [StockLocation](../stock/stock.md#stock-location) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| location | The [StockLocation](./context_variables.md#stocklocation) object itself |
|
||||
| --- | --- |
|
||||
| location | The StockLocation object itself |
|
||||
| qr_data | Formatted QR code data for the StockLocation |
|
||||
| parent | The parent StockLocation object |
|
||||
| stock_location | The StockLocation object itself (shadow of 'location') |
|
||||
| stock_items | Query set of all StockItem objects which are located in the StockLocation |
|
||||
|
||||
::: stock.models.StockLocation.report_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
|
||||
### Part
|
||||
|
||||
When printing a report or label against a [Part](../part/part.md) object, the following context variables are available:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| bom_items | Query set of all BomItem objects associated with the Part |
|
||||
| category | The PartCategory object associated with the Part |
|
||||
| description | The description field of the Part |
|
||||
| IPN | The IPN (internal part number) of the Part |
|
||||
| name | The name of the Part |
|
||||
| parameters | Dict object containing the parameters associated with the Part |
|
||||
| part | The Part object itself |
|
||||
| qr_data | Formatted QR code data for the Part |
|
||||
| qr_url | Generated URL for embedding in a QR code |
|
||||
| revision | The revision of the Part |
|
||||
| test_template_list | List of test templates associated with the Part |
|
||||
| test_templates | Dict object of test templates associated with the Part |
|
||||
|
||||
::: part.models.Part.report_context
|
||||
options:
|
||||
show_source: True
|
||||
|
||||
## Model Variables
|
||||
|
||||
Additional to the context variables provided directly to each template, each model type has a number of attributes and methods which can be accessedd via the template.
|
||||
|
||||
For each model type, a subset of the most commonly used attributes are listed below. For a full list of attributes and methods, refer to the source code for the particular model type.
|
||||
|
||||
### Parts
|
||||
|
||||
!!! incomplete "TODO"
|
||||
This section requires further work
|
||||
|
||||
#### Part
|
||||
Each part object has access to a lot of context variables about the part. The following context variables are provided when accessing a `Part` object:
|
||||
|
||||
Each part object has access to a lot of context variables about the part. The following context variables are provided when accessing a `Part` object from within the template.
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
@ -106,6 +287,7 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
|
||||
#### Part Category
|
||||
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| name | Name of this category |
|
||||
@ -117,6 +299,7 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
|
||||
#### StockItem
|
||||
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| parent | Link to another [StockItem](./context_variables.md#stockitem) from which this StockItem was created |
|
||||
@ -139,7 +322,7 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
| notes | Extra notes field |
|
||||
| build | Link to a Build (if this stock item was created from a build) |
|
||||
| is_building | Boolean field indicating if this stock item is currently being built (or is "in production") |
|
||||
| purchase_order | Link to a [PurchaseOrder](./context_variables.md#purchaseorder) (if this stock item was created from a PurchaseOrder) |
|
||||
| purchase_order | Link to a [PurchaseOrder](./context_variables.md#purchase-order) (if this stock item was created from a PurchaseOrder) |
|
||||
| infinite | If True this [StockItem](./context_variables.md#stockitem) can never be exhausted |
|
||||
| sales_order | Link to a [SalesOrder](./context_variables.md#salesorder) object (if the StockItem has been assigned to a SalesOrder) |
|
||||
| purchase_price | The unit purchase price for this [StockItem](./context_variables.md#stockitem) - this is the unit price at time of purchase (if this item was purchased from an external supplier) |
|
||||
@ -164,6 +347,7 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
|
||||
#### Company
|
||||
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| name | Name of the company |
|
||||
@ -184,6 +368,7 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
|
||||
#### Address
|
||||
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| line1 | First line of the postal address |
|
||||
@ -194,9 +379,6 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
|
||||
#### Contact
|
||||
|
||||
Contacts are added to companies. Actually the company has no link to the contacts.
|
||||
You can search the company object of the contact.
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| company | Company object where the contact belongs to |
|
||||
@ -207,6 +389,7 @@ You can search the company object of the contact.
|
||||
|
||||
#### SupplierPart
|
||||
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| part | Link to the master Part (Obsolete) |
|
||||
@ -226,24 +409,13 @@ You can search the company object of the contact.
|
||||
| has_price_breaks | Whether this [SupplierPart](./context_variables.md#supplierpart) has price breaks |
|
||||
| manufacturer_string | Format a MPN string for this [SupplierPart](./context_variables.md#supplierpart). Concatenates manufacture name and part number. |
|
||||
|
||||
### Manufacturers
|
||||
|
||||
!!! incomplete "TODO"
|
||||
This section requires further work
|
||||
|
||||
#### Manufacturer
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
|
||||
#### ManufacturerPart
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
|
||||
### Orders
|
||||
|
||||
The [Purchase Order](../order/purchase_order.md) context variables are described in the [Purchase Order](./purchase_order.md) section.
|
||||
#### Purchase Order
|
||||
|
||||
!!! note "TODO"
|
||||
This section is incomplete
|
||||
|
||||
#### SalesOrder
|
||||
|
||||
|
@ -18,7 +18,7 @@ Some common functions are provided for use in custom report and label templates.
|
||||
|
||||
When making use of helper functions within a template, it can be useful to store the result of the function to a variable, rather than immediately rendering the output.
|
||||
|
||||
For example, using the [render_currency](#rendering-currency) helper function, we can store the output to a variable which can be used at a later point in the template:
|
||||
For example, using the [render_currency](#currency-formatting) helper function, we can store the output to a variable which can be used at a later point in the template:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
@ -272,7 +272,7 @@ A template tag is provided to load the InvenTree logo image into a report. You c
|
||||
|
||||
### Custom Logo
|
||||
|
||||
If the system administrator has enabled a [custom logo](../start/config.md#customisation-options), then this logo will be used instead of the base InvenTree logo.
|
||||
If the system administrator has enabled a [custom logo](../start/config.md#customization-options) then this logo will be used instead of the base InvenTree logo.
|
||||
|
||||
This is a useful way to get a custom company logo into your reports.
|
||||
|
||||
@ -287,7 +287,7 @@ If you have a custom logo, but explicitly wish to load the InvenTree logo itself
|
||||
|
||||
## Report Assets
|
||||
|
||||
[Report Assets](./report.md#report-assets) are files specifically uploaded by the user for inclusion in generated reports and labels.
|
||||
[Report Assets](./templates.md#report-assets) are files specifically uploaded by the user for inclusion in generated reports and labels.
|
||||
|
||||
You can add asset images to the reports and labels by using the `{% raw %}{% asset ... %}{% endraw %}` template tag:
|
||||
|
||||
|
@ -11,17 +11,6 @@ Custom labels can be generated using simple HTML templates, with support for QR-
|
||||
|
||||
Simple (generic) label templates are supplied 'out of the box' with InvenTree - however support is provided for generation of extremely specific custom labels, to meet any particular requirement.
|
||||
|
||||
## Label Types
|
||||
|
||||
The following types of labels are available
|
||||
|
||||
| Label Type | Description |
|
||||
| --- | --- |
|
||||
| [Part Labels](./labels/part_labels.md) | Print labels for individual parts |
|
||||
| [Stock Labels](./labels/stock_labels.md) | Print labels for individual stock items |
|
||||
| [Location Labels](./labels/location_labels.md) | Print labels for individual stock locations
|
||||
| [Build Labels](./labels/build_labels.md) | Print labels for individual build order line items |
|
||||
|
||||
## Label Templates
|
||||
|
||||
Label templates are written using a mixture of [HTML](https://www.w3schools.com/html/) and [CSS](https://www.w3schools.com/css). [Weasyprint](https://weasyprint.org/) templates support a *subset* of HTML and CSS features. In addition to supporting HTML and CSS formatting, the label templates support the Django templating engine, allowing conditional formatting of the label data.
|
||||
|
@ -1,118 +0,0 @@
|
||||
---
|
||||
title: Build Labels
|
||||
---
|
||||
|
||||
## Build Line Labels
|
||||
|
||||
Build label templates are used to generate labels for individual build order line items.
|
||||
|
||||
### Creating Build Line Label Templates
|
||||
|
||||
Build label templates are added (and edited) via the [admin interface](../../settings/admin.md).
|
||||
|
||||
### Printing Build Line Labels
|
||||
|
||||
Build line labels are printed from the Build Order page, under the *Allocate Stock* tab. Multiple line items can be selected for printing:
|
||||
|
||||
{% with id='print_build_labels', url='report/label_build_print.png', description='Print build line labels' %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Context Data
|
||||
|
||||
The following context variables are made available to the Build Line label template:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| build_line | The build_line instance |
|
||||
| build | The build order to which the build_line is linked |
|
||||
| bom_item | The bom_item to which the build_line is linked |
|
||||
| part | The required part for this build_line instance. References bom_item.sub_part |
|
||||
| quantity | The total quantity required for the build line |
|
||||
| allocated_quantity | The total quantity which has been allocated against the build line |
|
||||
| allocations | A queryset containing the allocations made against the build_line |
|
||||
|
||||
## Example
|
||||
|
||||
A simple example template is shown below:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% extends "label/label_base.html" %}
|
||||
{% load barcode report %}
|
||||
{% load inventree_extras %}
|
||||
|
||||
{% block style %}
|
||||
|
||||
{{ block.super }}
|
||||
|
||||
.label {
|
||||
margin: 1mm;
|
||||
}
|
||||
|
||||
.qr {
|
||||
height: 28mm;
|
||||
width: 28mm;
|
||||
position: relative;
|
||||
top: 0mm;
|
||||
right: 0mm;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.label-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1pt solid black;
|
||||
}
|
||||
|
||||
.label-table tr {
|
||||
width: 100%;
|
||||
border-bottom: 1pt solid black;
|
||||
padding: 2.5mm;
|
||||
}
|
||||
|
||||
.label-table td {
|
||||
padding: 3mm;
|
||||
}
|
||||
|
||||
{% endblock style %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class='label'>
|
||||
<table class='label-table'>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Build Order:</b> {{ build.reference }}<br>
|
||||
<b>Build Qty:</b> {% decimal build.quantity %}<br>
|
||||
</td>
|
||||
<td>
|
||||
<img class='qr' alt='build qr' src='{% qrcode build.barcode %}'>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Part:</b> {{ part.name }}<br>
|
||||
{% if part.IPN %}
|
||||
<b>IPN:</b> {{ part.IPN }}<br>
|
||||
{% endif %}
|
||||
<b>Qty / Unit:</b> {% decimal bom_item.quantity %} {% if part.units %}[{{ part.units }}]{% endif %}<br>
|
||||
<b>Qty Total:</b> {% decimal quantity %} {% if part.units %}[{{ part.units }}]{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<img class='qr' alt='part qr' src='{% qrcode part.barcode %}'>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Which results in a label like:
|
||||
|
||||
{% with id='build_label_example', url='report/label_build_example.png', description='Example build line labels' %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
@ -1,24 +0,0 @@
|
||||
---
|
||||
title: Location Labels
|
||||
---
|
||||
|
||||
|
||||
## Stock Location Labels
|
||||
|
||||
Stock Location label templates are used to generate labels for individual Stock Locations.
|
||||
|
||||
### Creating Stock Location Label Templates
|
||||
|
||||
Stock Location label templates are added (and edited) via the admin interface.
|
||||
|
||||
### Printing Stock Location Labels
|
||||
|
||||
To print a single label from the Stock Location detail view, select the *Print Label* option.
|
||||
|
||||
### Context Data
|
||||
|
||||
The following variables are made available to the StockLocation label template:
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| location | The [StockLocation](../context_variables.md#stocklocation) object itself |
|
@ -1,91 +0,0 @@
|
||||
---
|
||||
title: Part Labels
|
||||
---
|
||||
|
||||
|
||||
## Part Labels
|
||||
|
||||
Part label templates are used to generate labels for individual Part instances.
|
||||
|
||||
### Creating Part Label Templates
|
||||
|
||||
Part label templates are added (and edited) via the admin interface.
|
||||
|
||||
### Printing Part Labels
|
||||
|
||||
Part label can be printed using the following approaches:
|
||||
|
||||
To print a single part label from the Part detail view, select the *Print Label* option.
|
||||
|
||||
To print multiple part labels, select multiple parts in the part table and select the *Print Labels* option.
|
||||
|
||||
### Context Data
|
||||
|
||||
The following context variables are made available to the Part label template:
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| part | The [Part](../context_variables.md#part) object |
|
||||
| category | The [Part Category](../context_variables.md#part-category) which contains the Part |
|
||||
| name | The name of the part |
|
||||
| description | The description text for the part |
|
||||
| IPN | Internal part number (IPN) for the part |
|
||||
| revision | Part revision code |
|
||||
| qr_data | String data which can be rendered to a QR code |
|
||||
| parameters | Map (Python dictionary) object containing the parameters associated with the part instance |
|
||||
|
||||
#### Parameter Values
|
||||
|
||||
The part parameter *values* can be accessed by parameter name lookup in the template, as follows:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
|
||||
Part: {{ part.name }}
|
||||
Length: {{ parameters.length }}
|
||||
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! warning "Spaces"
|
||||
Note that for parameters which include a `space` character in their name, lookup using the "dot" notation won't work! In this case, try using the [key lookup](../helpers.md#key-access) method:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
|
||||
Voltage Rating: {% getkey parameters "Voltage Rating" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
#### Parameter Data
|
||||
|
||||
If you require access to the parameter data itself, and not just the "value" of a particular parameter, you can use the `part_parameter` [helper function](../helpers.md#part-parameters).
|
||||
|
||||
For example, the following label template can be used to generate a label which contains parameter data in addition to parameter units:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% extends "label/label_base.html" %}
|
||||
|
||||
{% load report %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% part_parameter part "Width" as width %}
|
||||
{% part_parameter part "Length" as length %}
|
||||
|
||||
<div>
|
||||
Part: {{ part.full_name }}<br>
|
||||
Width: {{ width.data }} [{{ width.units }}]<br>
|
||||
Length: {{ length.data }} [{{ length.units }}]
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
The following label is produced:
|
||||
|
||||
{% with id="report-parameters", url="report/label_with_parameters.png", description="Label with parameters" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
@ -1,61 +0,0 @@
|
||||
---
|
||||
title: Stock Labels
|
||||
---
|
||||
|
||||
|
||||
## Stock Item Labels
|
||||
|
||||
Stock Item label templates are used to generate labels for individual Stock Items.
|
||||
|
||||
### Creating Stock Item Label Templates
|
||||
|
||||
Stock Item label templates are added (and edited) via the admin interface.
|
||||
|
||||
### Printing Stock Item Labels
|
||||
|
||||
Stock Item labels can be printed using the following approaches:
|
||||
|
||||
To print a single stock item from the Stock Item detail view, select the *Print Label* option as shown below:
|
||||
|
||||
{% with id='item_label_single', url='report/label_stock_print_single.png', description='Print single stock item label' %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
To print multiple stock items from the Stock table view, select the *Print Labels* option as shown below:
|
||||
|
||||
{% with id='item_label_multiple', url='report/label_stock_print_multiple.png', description='Print multiple stock item labels' %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Context Data
|
||||
|
||||
The following variables are made available to the StockItem label template:
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| item | The [StockItem](../context_variables.md#stockitem) object itself |
|
||||
| part | The [Part](../context_variables.md#part) object which is referenced by the [StockItem](../context_variables.md#stockitem) object |
|
||||
| name | The `name` field of the associated Part object |
|
||||
| ipn | The `IPN` field of the associated Part object |
|
||||
| revision | The `revision` field of the associated Part object |
|
||||
| quantity | The `quantity` field of the StockItem object |
|
||||
| serial | The `serial` field of the StockItem object |
|
||||
| uid | The `uid` field of the StockItem object |
|
||||
| tests | Dict object of TestResult data associated with the StockItem |
|
||||
| parameters | Dict object containing the parameters associated with the base Part |
|
||||
|
||||
### URL-style QR code
|
||||
|
||||
Stock Item labels support [QR code](../barcodes.md#qr-code) containing the stock item URL, which can be
|
||||
scanned and opened directly
|
||||
on a portable device using the camera or a QR code scanner. To generate a URL-style QR code for stock item in the [label HTML template](../labels.md#label-templates), add the
|
||||
following HTML tag:
|
||||
|
||||
``` html
|
||||
{% raw %}
|
||||
<img class='custom_qr_class' src='{% qrcode qr_url %}'>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Make sure to customize the `custom_qr_class` CSS class to define the position of the QR code
|
||||
on the label.
|
@ -1,65 +0,0 @@
|
||||
---
|
||||
title: Purchase Order Report
|
||||
---
|
||||
|
||||
## Purchase Order Reports
|
||||
|
||||
Custom purchase order reports may be generated against any given [Purchase Order](../order/purchase_order.md). For example, purchase order reports could be used to generate a pdf of the order to send to a supplier.
|
||||
|
||||
### Purchase Order Filters
|
||||
|
||||
The report template can be filtered against available [Purchase Order](../order/purchase_order.md) instances.
|
||||
|
||||
### Context Variables
|
||||
|
||||
In addition to the default report context variables, the following variables are made available to the purchase order report template for rendering:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| order | The specific Purchase Order object |
|
||||
| reference | The order reference field (can also be accessed as `{% raw %}{{ order.reference }}{% endraw %}`) |
|
||||
| description | The order description field |
|
||||
| supplier | The [supplier](../order/company.md#suppliers) associated with this purchase order |
|
||||
| lines | A list of available line items for this order |
|
||||
| extra_lines | A list of available *extra* line items for this order |
|
||||
| order.created_by | The user who created the order |
|
||||
| order.responsible | The user or group who is responsible for the order |
|
||||
| order.creation_date | The date when the order was created |
|
||||
| order.target_date | The date when the order should arrive |
|
||||
| order.if_overdue | Boolean value that tells if the target date has passed |
|
||||
| order.currency | The currency code associated with this order, e.g. 'AUD' |
|
||||
| order.contact | The [contact](./context_variables.md#contact) object associated with this order |
|
||||
|
||||
#### Lines
|
||||
|
||||
Each line item (available within the `lines` list) has sub variables, as follows:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| quantity | The quantity of the part to be ordered |
|
||||
| part | The [supplierpart ](./context_variables.md#supplierpart) object to be ordered |
|
||||
| reference | The reference given in the part of the order |
|
||||
| notes | The notes given in the part of the order |
|
||||
| target_date | The date when the part should arrive. Each part can have an individual date |
|
||||
| price | The unit price the line item |
|
||||
| total_line_price | The total price for this line item, calculated from the unit price and quantity |
|
||||
| destination | The stock location where the part will be stored |
|
||||
|
||||
A simple example below shows how to use the context variables for each line item:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% for line in lines %}
|
||||
Internal Part: {{ line.part.part.name }} - <i>{{ line.part.part.description }}</i>
|
||||
SKU: {{ line.part.SKU }}
|
||||
Price: {% render_currency line.total_line_price %}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default *Purchase Order Report* template is provided out of the box, which is useful for generating simple test reports. Furthermore, it may be used as a starting point for developing custom BOM reports:
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_po_report_base.html) for the default purchase order report template.
|
@ -1,14 +1,14 @@
|
||||
---
|
||||
title: Report Generation
|
||||
title: Report and LabelGeneration
|
||||
---
|
||||
|
||||
## Custom Reporting
|
||||
## Custom Reports
|
||||
|
||||
InvenTree supports a customizable reporting ecosystem, allowing the user to develop reporting templates that meet their particular needs.
|
||||
InvenTree supports a customizable reporting ecosystem, allowing the user to develop document templates that meet their particular needs.
|
||||
|
||||
PDF reports are generated from custom HTML template files which are written by the user.
|
||||
PDF files are generated from custom HTML template files which are written by the user.
|
||||
|
||||
Reports are used in a variety of situations to format data in a friendly format for printing, distribution, conformance and testing.
|
||||
Templates can be used to generate *reports* or *labels* which can be used in a variety of situations to format data in a friendly format for printing, distribution, conformance and testing.
|
||||
|
||||
In addition to providing the ability for end-users to provide their own reporting templates, some report types offer "built-in" report templates ready for use.
|
||||
|
||||
@ -44,290 +44,3 @@ For example, rendering the name of a part (which is available in the particular
|
||||
</p></i>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
### Context Variables
|
||||
|
||||
!!! info "Context Variables"
|
||||
Templates will have different variables available to them depending on the report type. Read the detailed information on each available report type for further information.
|
||||
|
||||
Please refer to the [Context variables](./context_variables.md) page.
|
||||
|
||||
### Conditional Rendering
|
||||
|
||||
The django template system allows for conditional rendering, providing conditional flow statements such as:
|
||||
|
||||
```
|
||||
{% raw %}
|
||||
{% if <condition> %}
|
||||
{% do_something %}
|
||||
{% elif <other_condition> %}
|
||||
<!-- something else -->
|
||||
{% else %}
|
||||
<!-- finally -->
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
```
|
||||
{% raw %}
|
||||
{% for <item> in <list> %}
|
||||
Item: {{ item }}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! info "Conditionals"
|
||||
Refer to the [django template language documentation]({% include "django.html" %}/ref/templates/language/) for more information.
|
||||
|
||||
### Localization Issues
|
||||
|
||||
Depending on your localization scheme, inputting raw numbers into the formatting section template can cause some unintended issues. Consider the block below which specifies the page size for a rendered template:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: {{ width }}mm {{ height }}mm;
|
||||
margin: 0mm;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
If localization settings on the InvenTree server use a comma (`,`) character as a decimal separator, this may produce an output like:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% endraw %}
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: 57,3mm 99,0mm;
|
||||
margin: 0mm;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
```
|
||||
|
||||
The resulting `{% raw %}<style>{% endraw %}` CSS block will be *invalid*!
|
||||
|
||||
So, if you are writing a template which has custom formatting, (or any other sections which cannot handle comma decimal separators) you must wrap that section in a `{% raw %}{% localize off %}{% endraw %}` block:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% load l10n %}
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
{% localize off %}
|
||||
size: {{ width }}mm {{ height }}mm;
|
||||
{% endlocalize %}
|
||||
margin: 0mm;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! tip "Close it out"
|
||||
Don't forget to end with a `{% raw %}{% endlocalize %}{% endraw %}` tag!
|
||||
|
||||
!!! tip "l10n"
|
||||
You will need to add `{% raw %}{% load l10n %}{% endraw %}` to the top of your template file to use the `{% raw %}{% localize %}{% endraw %}` tag.
|
||||
|
||||
### Extending with Plugins
|
||||
|
||||
The [ReportMixin plugin class](../extend/plugins/report.md) allows reporting functionality to be extended with custom features.
|
||||
|
||||
## Report Types
|
||||
|
||||
InvenTree supports the following reporting functionality:
|
||||
|
||||
| Report Type | Description |
|
||||
| --- | --- |
|
||||
| [Test Report](./test.md) | Format results of a test report against for a particular StockItem |
|
||||
| [Build Order Report](./build.md) | Format a build order report |
|
||||
| [Purchase Order Report](./purchase_order.md) | Format a purchase order report |
|
||||
| [Sales Order Report](./sales_order.md) | Format a sales order report |
|
||||
| [Return Order Report](./return_order.md) | Format a return order report |
|
||||
| [Stock Location Report](./stock_location.md) | Format a stock location report |
|
||||
|
||||
### Default Reports
|
||||
|
||||
InvenTree is supplied with a number of default templates "out of the box". These are generally quite simple, but serve as a starting point for building custom reports to suit a specific need.
|
||||
|
||||
!!! tip "Read the Source"
|
||||
The source code for the default reports is [available on GitHub](https://github.com/inventree/InvenTree/tree/master/src/backend/InvenTree/report/templates/report). Use this as a guide for generating your own reports!
|
||||
|
||||
## Creating Reports
|
||||
|
||||
Report templates are created (and edited) via the [admin interface](../settings/admin.md), under the *Report* section. Select the certain type of report template you are wanting to create, and press the *Add* button in the top right corner:
|
||||
|
||||
{% with id="report-create", url="report/add_report_template.png", description="Create new report" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
!!! tip "Staff Access Only"
|
||||
Only users with staff access can upload or edit report template files.
|
||||
|
||||
!!! info "Editing Reports"
|
||||
Existing reports can be edited from the admin interface, in the same location as described above. To change the contents of the template, re-upload a template file, to override the existing template data.
|
||||
|
||||
### Name and Description
|
||||
|
||||
Each report template requires a name and description, which identify and describe the report template.
|
||||
|
||||
### Enabled Status
|
||||
|
||||
Boolean field which determines if the specific report template is enabled, and available for use. Reports can be disabled to remove them from the list of available templates, but without deleting them from the database.
|
||||
|
||||
### Filename Pattern
|
||||
|
||||
The filename pattern used to generate the output `.pdf` file. Defaults to "report.pdf".
|
||||
|
||||
The filename pattern allows custom rendering with any context variables which are available to the report. For example, a [test report](./test.md) for a particular [Stock Item](../stock/stock.md#stock-item) can use the part name and serial number of the stock item when generating the report name:
|
||||
|
||||
{% with id="report-filename-pattern", url="report/filename_pattern.png", description="Report filename pattern" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
|
||||
### Report Filters
|
||||
|
||||
Each type of report provides a *filters* field, which can be used to filter which items a report can be generated against. The target of the *filters* field depends on the type of report - refer to the documentation on the specific report type for more information.
|
||||
|
||||
For example, the [Test Report](./test.md) filter targets the linked [Stock Item](../stock/status.md) object, and can be used to select which stock items are allowed for the given report. Let's say that a certain test report should only be generated for "trackable" stock items. A filter could easily be constructed to accommodate this, by limiting available items to those where the associated [Part](../part/part.md) is *trackable*:
|
||||
|
||||
{% with id="report-filter-valid", url="report/filters_valid.png", description="Report filter selection" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
If you enter an invalid option for the filter field, an error message will be displayed:
|
||||
|
||||
{% with id="report-filter-invalid", url="report/filters_invalid.png", description="Invalid filter selection" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
!!! warning "Advanced Users"
|
||||
Report filtering is an advanced topic, and requires a little bit of knowledge of the underlying data structure!
|
||||
|
||||
### Metadata
|
||||
|
||||
A JSON field made available to any [plugins](../extend/plugins.md) - but not used by internal code.
|
||||
|
||||
## Report Options
|
||||
|
||||
A number of global reporting options are available for customizing InvenTree reports:
|
||||
|
||||
{% with id="report-options", url="report/report.png", description="Report Options" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Enable Reports
|
||||
|
||||
By default, the reporting feature is disabled. It must be enabled in the global settings.
|
||||
|
||||
|
||||
### Default Page Size
|
||||
|
||||
The built-in InvenTree report templates (and any reports which are derived from the built-in templates) use the *Page Size* option to set the page size of the generated reports.
|
||||
|
||||
!!! info "Override Page Size"
|
||||
Custom report templates do not have to make use of the *Page Size* option, although it is made available to the template context.
|
||||
|
||||
### Debug Mode
|
||||
|
||||
As templates are rendered directly to a PDF object, it can be difficult to debug problems when the PDF does not render exactly as expected.
|
||||
|
||||
Setting the *Debug Mode* option renders the template as raw HTML instead of PDF, allowing the rendering output to be introspected. This feature allows template designers to understand any issues with the generated HTML (before it is passed to the PDF generation engine).
|
||||
|
||||
!!! warning "HTML Rendering Limitations"
|
||||
When rendered in debug mode, @page attributes (such as size, etc) will **not** be observed. Additionally, any asset files stored on the InvenTree server will not be rendered. Debug mode is not intended to produce "good looking" documents!
|
||||
|
||||
## Report Assets
|
||||
|
||||
User can upload asset files (e.g. images) which can be used when generating reports. For example, you may wish to generate a report with your company logo in the header. Asset files are uploaded via the admin interface.
|
||||
|
||||
Asset files can be rendered directly into the template as follows
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<!-- Need to include the report template tags at the start of the template file -->
|
||||
{% load report %}
|
||||
|
||||
<!-- Simple stylesheet -->
|
||||
<head>
|
||||
<style>
|
||||
.company-logo {
|
||||
height: 50px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Report template code here -->
|
||||
|
||||
<!-- Render an uploaded asset image -->
|
||||
<img src="{% asset 'company_image.png' %}" class="company-logo">
|
||||
|
||||
<!-- ... -->
|
||||
</body>
|
||||
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! warning "Asset Naming"
|
||||
If the requested asset name does not match the name of an uploaded asset, the template will continue without loading the image.
|
||||
|
||||
!!! info "Assets location"
|
||||
You need to ensure your asset images to the report/assets directory in the [data directory](../start/intro.md#file-storage). Upload new assets via the [admin interface](../settings/admin.md) to ensure they are uploaded to the correct location on the server.
|
||||
|
||||
|
||||
## Report Snippets
|
||||
|
||||
A powerful feature provided by the django / WeasyPrint templating framework is the ability to include external template files. This allows commonly used template features to be broken out into separate files and re-used across multiple templates.
|
||||
|
||||
To support this, InvenTree provides report "snippets" - short (or not so short) template files which cannot be rendered by themselves, but can be called from other templates.
|
||||
|
||||
Similar to assets files, snippet template files are uploaded via the admin interface.
|
||||
|
||||
Snippets are included in a template as follows:
|
||||
|
||||
```
|
||||
{% raw %}{% include 'snippets/<snippet_name.html>' %}{% endraw %}
|
||||
```
|
||||
|
||||
For example, consider a stocktake report for a particular stock location, where we wish to render a table with a row for each item in that location.
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
|
||||
<table class='stock-table'>
|
||||
<thead>
|
||||
<!-- table header data -->
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in location.stock_items %}
|
||||
{% include 'snippets/stock_row.html' with item=item %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! info "Snippet Arguments"
|
||||
Note above that named argument variables can be passed through to the snippet!
|
||||
|
||||
And the snippet file `stock_row.html` may be written as follows:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<!-- stock_row snippet -->
|
||||
<tr>
|
||||
<td>{{ item.part.full_name }}</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
</tr>
|
||||
{% endraw %}
|
||||
```
|
||||
|
@ -1,26 +0,0 @@
|
||||
---
|
||||
title: Return Order Reports
|
||||
---
|
||||
|
||||
## Return Order Reports
|
||||
|
||||
Custom reports may be generated against any given [Return Order](../order/return_order.md). For example, return order reports can be used to generate an RMA request to send to a customer.
|
||||
|
||||
### Context Variables
|
||||
|
||||
In addition to the default report context variables, the following context variables are made available to the return order report template for rendering:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| order | The return order object the report is being generated against |
|
||||
| description | The description of the order, also accessed through `order.description` |
|
||||
| reference | The reference of the order, also accessed through `order.reference` |
|
||||
| customer | The customer object related to this order |
|
||||
| lines | The list of line items linked to this order |
|
||||
| extra_lines | The list of extra line items linked to this order |
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default report template is provided out of the box, which can be used as a starting point for developing custom return order report templates.
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_return_order_report_base.html) for the default return order report template.
|
@ -1,31 +0,0 @@
|
||||
---
|
||||
title: Sales Order Reports
|
||||
---
|
||||
|
||||
## Sales Order Reports
|
||||
|
||||
Custom sales order reports may be generated against any given [Sales Order](../order/sales_order.md). For example, a sales order report could be used to generate an invoice to send to a customer.
|
||||
|
||||
### Sales Order Filters
|
||||
|
||||
The report template can be filtered against available [Sales Order](../order/sales_order.md) instances.
|
||||
|
||||
### Context Variables
|
||||
|
||||
In addition to the default report context variables, the following variables are made available to the sales order report template for rendering:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| order | The specific Sales Order object |
|
||||
| reference | The order reference field (can also be accessed as `{% raw %}{{ order.description }}{% endraw %}`) |
|
||||
| description | The order description field |
|
||||
| customer | The [customer](../order/company.md#customers) associated with the particular sales order |
|
||||
| lines | A list of available line items for this order |
|
||||
| extra_lines | A list of available *extra* line items for this order |
|
||||
| order.currency | The currency code associated with this order, e.g. 'CAD' |
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default *Sales Order Report* template is provided out of the box, which is useful for generating simple test reports. Furthermore, it may be used as a starting point for developing custom BOM reports:
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_so_report_base.html) for the default sales order report template.
|
78
docs/docs/report/samples.md
Normal file
78
docs/docs/report/samples.md
Normal file
@ -0,0 +1,78 @@
|
||||
---
|
||||
title: Sample Templates
|
||||
---
|
||||
|
||||
## Sample Templates
|
||||
|
||||
A number of pre-built templates are provided with InvenTree, which can be used as a starting point for creating custom reports and labels.
|
||||
|
||||
Users can create their own custom templates, or modify the provided templates to suit their needs.
|
||||
|
||||
## Report Templates
|
||||
|
||||
The following report templates are provided "out of the box" and can be used as a starting point, or as a reference for creating custom reports templates:
|
||||
|
||||
| Template | Model Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [Bill of Materials](#bill-of-materials-report) | [Part](../part/part.md) | Bill of Materials report |
|
||||
| [Build Order](#build-order) | [BuildOrder](../build/build.md) | Build Order report |
|
||||
| [Purchase Order](#purchase-order) | [PurchaseOrder](../order/purchase_order.md) | Purchase Order report |
|
||||
| [Return Order](#return-order) | [ReturnOrder](../order/return_order.md) | Return Order report |
|
||||
| [Sales Order](#sales-order) | [SalesOrder](../order/sales_order.md) | Sales Order report |
|
||||
| [Stock Location](#stock-location) | [StockLocation](../stock/stock.md#stock-location) | Stock Location report |
|
||||
| [Test Report](#test-report) | [StockItem](../stock/stock.md#stock-item) | Test Report |
|
||||
|
||||
### Bill of Materials Report
|
||||
|
||||
{{ templatefile("report/inventree_bill_of_materials_report.html") }}
|
||||
|
||||
### Build Order
|
||||
|
||||
{{ templatefile("report/inventree_build_order_report.html") }}
|
||||
|
||||
### Purchase Order
|
||||
|
||||
{{ templatefile("report/inventree_bill_of_materials_report.html") }}
|
||||
|
||||
### Return Order
|
||||
|
||||
{{ templatefile("report/inventree_return_order_report.html") }}
|
||||
|
||||
### Sales Order
|
||||
|
||||
{{ templatefile("report/inventree_sales_order_report.html") }}
|
||||
|
||||
### Stock Location
|
||||
|
||||
{{ templatefile("report/inventree_stock_location_report.html") }}
|
||||
|
||||
### Test Report
|
||||
|
||||
{{ templatefile("report/inventree_test_report.html") }}
|
||||
|
||||
## Label Templates
|
||||
|
||||
The following label templates are provided "out of the box" and can be used as a starting point, or as a reference for creating custom label templates:
|
||||
|
||||
| Template | Model Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [Build Line](#build-line-label) | [Build line item](../build/build.md) | Build Line label |
|
||||
| [Part](#part-label) | [Part](../part/part.md) | Part label |
|
||||
| [Stock Item](#stock-item-label) | [StockItem](../stock/stock.md#stock-item) | Stock Item label |
|
||||
| [Stock Location](#stock-location-label) | [StockLocation](../stock/stock.md#stock-location) | Stock Location label |
|
||||
|
||||
### Build Line Label
|
||||
|
||||
{{ templatefile("label/buildline_label.html") }}
|
||||
|
||||
### Part Label
|
||||
|
||||
{{ templatefile("label/part_label_code128.html") }}
|
||||
|
||||
### Stock Item Label
|
||||
|
||||
{{ templatefile("label/stockitem_qr.html") }}
|
||||
|
||||
### Stock Location Label
|
||||
|
||||
{{ templatefile("label/stocklocation_qr_and_text.html") }}
|
@ -1,16 +0,0 @@
|
||||
---
|
||||
title: Stock Location Reports
|
||||
---
|
||||
|
||||
## Stock location Reports
|
||||
|
||||
You can print a formatted report of a stock location. This makes sense if you have several parts inside one location, e.g. a box that is sent out to a manufacturing partner. Whit a report you can create a box content list.
|
||||
|
||||
### Context Variables
|
||||
You can use all content variables from the [StockLocation](./context_variables.md#stocklocation) object.
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default report template is provided out of the box, which can be used as a starting point for developing custom return order report templates.
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_slr_report.html) for the default stock location report template.
|
228
docs/docs/report/templates.md
Normal file
228
docs/docs/report/templates.md
Normal file
@ -0,0 +1,228 @@
|
||||
---
|
||||
title: InvenTree Templates
|
||||
---
|
||||
|
||||
## Template Overview
|
||||
|
||||
InvenTree supports a customizable reporting ecosystem, allowing the user to develop document templates that meet their particular needs.
|
||||
|
||||
PDF files are generated from custom HTML template files which are written by the user.
|
||||
|
||||
Templates can be used to generate *reports* or *labels* which can be used in a variety of situations to format data in a friendly format for printing, distribution, conformance and testing.
|
||||
|
||||
In addition to providing the ability for end-users to provide their own reporting templates, some report types offer "built-in" report templates ready for use.
|
||||
|
||||
## Template Types
|
||||
|
||||
The following types of templates are available:
|
||||
|
||||
### Reports
|
||||
|
||||
Reports are intended to serve as formal documents, and can be used to generate formatted PDF outputs for a variety of purposes.
|
||||
|
||||
Refer to the [report templates](./report.md) documentation for further information.
|
||||
|
||||
### Labels
|
||||
|
||||
Labels can also be generated using the templating system. Labels are intended to be used for printing small, formatted labels for items, parts, locations, etc.
|
||||
|
||||
Refer to the [label templates](./labels.md) documentation for further information.
|
||||
|
||||
### Template Model Types
|
||||
|
||||
When generating a particular template (to render a report or label output), the template is rendered against a particular "model" type. The model type determines the data that is available to the template, and how it is formatted.
|
||||
|
||||
To read more about the model types for which templates can be rendered, and the associated context information, refer to the [context variables](./context_variables.md) documentation.
|
||||
|
||||
### Default Reports
|
||||
|
||||
InvenTree is supplied with a number of default templates "out of the box" - for generating both labels and reports. These are generally quite simple, but serve as a starting point for building custom reports to suit a specific need.
|
||||
|
||||
!!! tip "Read the Source"
|
||||
The source code for the default reports is [available on GitHub](https://github.com/inventree/InvenTree/tree/master/src/backend/InvenTree/report/templates/report). Use this as a guide for generating your own reports!
|
||||
|
||||
### Extending with Plugins
|
||||
|
||||
The [ReportMixin plugin class](../extend/plugins/report.md) allows reporting functionality to be extended with custom features.
|
||||
|
||||
## WeasyPrint Template Rendering
|
||||
|
||||
InvenTree report templates utilize the powerful [WeasyPrint](https://weasyprint.org/) PDF generation engine.
|
||||
|
||||
To read more about the capabilities of the report templating engine, and how to use it, refer to the [weasyprint documentation](./weasyprint.md).
|
||||
|
||||
## Creating Templates
|
||||
|
||||
Report and label templates can be created (and edited) via the [admin interface](../settings/admin.md), under the *Report* section.
|
||||
|
||||
Select the type of template you are wanting to create (a *Report Template* or *Label Template*) and press the *Add* button in the top right corner:
|
||||
|
||||
{% with id="report-list", url="report/report_template_admin.png", description="Report templates in admin interface" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
!!! tip "Staff Access Only"
|
||||
Only users with staff access can upload or edit report template files.
|
||||
|
||||
!!! info "Editing Reports"
|
||||
Existing reports can be edited from the admin interface, in the same location as described above. To change the contents of the template, re-upload a template file, to override the existing template data.
|
||||
|
||||
!!! tip "Template Editor"
|
||||
InvenTree also provides a powerful [template editor](./template_editor.md) which allows for the creation and editing of report templates directly within the browser.
|
||||
|
||||
### Name and Description
|
||||
|
||||
Each report template requires a name and description, which identify and describe the report template.
|
||||
|
||||
### Enabled Status
|
||||
|
||||
Boolean field which determines if the specific report template is enabled, and available for use. Reports can be disabled to remove them from the list of available templates, but without deleting them from the database.
|
||||
|
||||
### Filename Pattern
|
||||
|
||||
The filename pattern used to generate the output `.pdf` file. Defaults to "report.pdf".
|
||||
|
||||
The filename pattern allows custom rendering with any context variables which are available to the report. For example, a test report for a particular [Stock Item](../stock/stock.md#stock-item) can use the part name and serial number of the stock item when generating the report name:
|
||||
|
||||
{% with id="report-filename-pattern", url="report/filename_pattern.png", description="Report filename pattern" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
|
||||
### Template Filters
|
||||
|
||||
Each template instance provides a *filters* field, which can be used to filter which items a report or label template can be generated against. The target of the *filters* field depends on the model type associated with the particular template.
|
||||
|
||||
As an example, let's say that a certain `StockItem` report should only be generated for "trackable" stock items. A filter could easily be constructed to accommodate this, by limiting available items to those where the associated [Part](../part/part.md) is *trackable*:
|
||||
|
||||
{% with id="report-filter-valid", url="report/filters_valid.png", description="Report filter selection" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
If you enter an invalid option for the filter field, an error message will be displayed:
|
||||
|
||||
{% with id="report-filter-invalid", url="report/filters_invalid.png", description="Invalid filter selection" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
!!! warning "Advanced Users"
|
||||
Report filtering is an advanced topic, and requires a little bit of knowledge of the underlying data structure!
|
||||
|
||||
### Metadata
|
||||
|
||||
A JSON field made available to any [plugins](../extend/plugins.md) - but not used by internal code.
|
||||
|
||||
## Reporting Options
|
||||
|
||||
A number of global reporting options are available for customizing InvenTree reports:
|
||||
|
||||
{% with id="report-options", url="report/report.png", description="Report Options" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Enable Reports
|
||||
|
||||
By default, the reporting feature is disabled. It must be enabled in the global settings.
|
||||
|
||||
|
||||
### Default Page Size
|
||||
|
||||
The built-in InvenTree report templates (and any reports which are derived from the built-in templates) use the *Page Size* option to set the page size of the generated reports.
|
||||
|
||||
!!! info "Override Page Size"
|
||||
Custom report templates do not have to make use of the *Page Size* option, although it is made available to the template context.
|
||||
|
||||
### Debug Mode
|
||||
|
||||
As templates are rendered directly to a PDF object, it can be difficult to debug problems when the PDF does not render exactly as expected.
|
||||
|
||||
Setting the *Debug Mode* option renders the template as raw HTML instead of PDF, allowing the rendering output to be introspected. This feature allows template designers to understand any issues with the generated HTML (before it is passed to the PDF generation engine).
|
||||
|
||||
!!! warning "HTML Rendering Limitations"
|
||||
When rendered in debug mode, @page attributes (such as size, etc) will **not** be observed. Additionally, any asset files stored on the InvenTree server will not be rendered. Debug mode is not intended to produce "good looking" documents!
|
||||
|
||||
## Report Assets
|
||||
|
||||
User can upload asset files (e.g. images) which can be used when generating reports. For example, you may wish to generate a report with your company logo in the header. Asset files are uploaded via the admin interface.
|
||||
|
||||
Asset files can be rendered directly into the template as follows
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<!-- Need to include the report template tags at the start of the template file -->
|
||||
{% load report %}
|
||||
|
||||
<!-- Simple stylesheet -->
|
||||
<head>
|
||||
<style>
|
||||
.company-logo {
|
||||
height: 50px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Report template code here -->
|
||||
|
||||
<!-- Render an uploaded asset image -->
|
||||
<img src="{% asset 'company_image.png' %}" class="company-logo">
|
||||
|
||||
<!-- ... -->
|
||||
</body>
|
||||
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! warning "Asset Naming"
|
||||
If the requested asset name does not match the name of an uploaded asset, the template will continue without loading the image.
|
||||
|
||||
!!! info "Assets location"
|
||||
You need to ensure your asset images to the report/assets directory in the [data directory](../start/intro.md#file-storage). Upload new assets via the [admin interface](../settings/admin.md) to ensure they are uploaded to the correct location on the server.
|
||||
|
||||
|
||||
## Report Snippets
|
||||
|
||||
A powerful feature provided by the django / WeasyPrint templating framework is the ability to include external template files. This allows commonly used template features to be broken out into separate files and re-used across multiple templates.
|
||||
|
||||
To support this, InvenTree provides report "snippets" - short (or not so short) template files which cannot be rendered by themselves, but can be called from other templates.
|
||||
|
||||
Similar to assets files, snippet template files are uploaded via the admin interface.
|
||||
|
||||
Snippets are included in a template as follows:
|
||||
|
||||
```
|
||||
{% raw %}{% include 'snippets/<snippet_name.html>' %}{% endraw %}
|
||||
```
|
||||
|
||||
For example, consider a stocktake report for a particular stock location, where we wish to render a table with a row for each item in that location.
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
|
||||
<table class='stock-table'>
|
||||
<thead>
|
||||
<!-- table header data -->
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in location.stock_items %}
|
||||
{% include 'snippets/stock_row.html' with item=item %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! info "Snippet Arguments"
|
||||
Note above that named argument variables can be passed through to the snippet!
|
||||
|
||||
And the snippet file `stock_row.html` may be written as follows:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<!-- stock_row snippet -->
|
||||
<tr>
|
||||
<td>{{ item.part.full_name }}</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
</tr>
|
||||
{% endraw %}
|
||||
```
|
@ -1,87 +0,0 @@
|
||||
---
|
||||
title: Test Report
|
||||
---
|
||||
|
||||
## Test Report
|
||||
|
||||
InvenTree provides [test result](../stock/test.md) tracking functionality which allows the users to keep track of any tests which have been performed on a given [stock item](../stock/stock.md).
|
||||
|
||||
Custom test reports may be generated against any given stock item. All testing data is made available to the template for custom rendering as required.
|
||||
|
||||
For example, an "Acceptance Test" report template may be customized to the particular device, with the results for certain tests rendering in a particular part of the page, with any tests which have not passed highlighted.
|
||||
|
||||
### Stock Item Filters
|
||||
|
||||
A TestReport template may define a set of filters against which stock items are sorted. Any [StockItem](../stock/stock.md) objects which match the provided filters can use the given TestReport.
|
||||
|
||||
This allows each TestReport to easily be assigned to a particular StockItem, or even multiple items.
|
||||
|
||||
In the example below, a test report template is uploaded and available to any stock items linked to a part with the name *"My Widget"*. Any combination of fields relevant to the StockItem model can be used here.
|
||||
|
||||
{% with id="test-report-filters", url="report/test_report_filters.png", description="Test report filters" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
|
||||
### Context Variables
|
||||
|
||||
In addition to the default report context variables, the following context variables are made available to the TestReport template for rendering:
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| stock_item | The individual [Stock Item](./context_variables.md#stockitem) object for which this test report is being generated |
|
||||
| serial | The serial number of the linked Stock Item |
|
||||
| part | The [Part](./context_variables.md#part) object of which the stock_item is an instance |
|
||||
| parameters | A dict object representing the [parameters](../part/parameter.md) of the referenced part |
|
||||
| test_keys | A list of the available 'keys' for the test results recorded against the stock item |
|
||||
| test_template_list | A list of the available [test templates](../part/test.md#part-test-templates) for the referenced part |
|
||||
| test_template_map | A map / dict of the available test templates |
|
||||
| results | A dict of test result objects, where the 'key' for each test result is a shortened version of the test name (see below) |
|
||||
| result_list | A list of each test result object |
|
||||
| installed_items | A flattened list representing all [Stock Item](./context_variables.md#stockitem) objects which are *installed inside* the referenced [Stock Item](./context_variables.md#stockitem) object |
|
||||
|
||||
#### Results
|
||||
|
||||
The *results* context variable provides a very convenient method of callout out a particular test result by name.
|
||||
|
||||
#### Example
|
||||
|
||||
Say for example that a Part "Electronic Widget" has a stock item with serial number #123, and has a test result uploaded called "Firmware Checksum". The templated file can reference this data as follows:
|
||||
|
||||
``` html
|
||||
<h3>Part: {% raw %}{{ part.name }}{% endraw %}</h3>
|
||||
<b>Serial Number: {% raw %}{{ stock_item.serial }}{% endraw %}</b>
|
||||
<hr>
|
||||
<p>
|
||||
Firmware Checksum: {% raw %}{{ results.firmwarechecksum.value }}.
|
||||
Uploaded by {{ results.firmwarechecksum.user }}{% endraw %}
|
||||
</p>
|
||||
```
|
||||
|
||||
#### Installed Items
|
||||
|
||||
The *installed_items* context variable is a list of all [StockItem](./context_variables.md#stockitem) instances which are installed inside the [StockItem](./context_variables.md#stockitem) referenced by the report template. Each [StockItem](./context_variables.md#stockitem) can be dereferenced as follows:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<table>
|
||||
{% for sub_item in installed_items %}
|
||||
<tr>
|
||||
<td>{{ sub_item.full_name }}</td>
|
||||
<td>Serial Number: {{ sub_item.serial }}</td>
|
||||
<td>Pass: {{ sub_item.passedAllRequiredTests }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
### Default Report Template
|
||||
|
||||
A default *Test Report* template is provided out of the box, which is useful for generating simple test reports. Furthermore, it may be used as a starting point for developing custom test reports:
|
||||
|
||||
{% with id="test-report-example", url="report/test_report_example.png", description="Example Test Report" %}
|
||||
{% include "img.html" %}
|
||||
{% endwith %}
|
||||
|
||||
View the [source code](https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/templates/report/inventree_test_report_base.html) for the default test report template.
|
111
docs/docs/report/weasyprint.md
Normal file
111
docs/docs/report/weasyprint.md
Normal file
@ -0,0 +1,111 @@
|
||||
---
|
||||
title: Weasyprint Templates
|
||||
---
|
||||
|
||||
## WeasyPrint Templates
|
||||
|
||||
We use the powerful [WeasyPrint](https://weasyprint.org/) PDF generation engine to create custom reports and labels.
|
||||
|
||||
!!! info "WeasyPrint"
|
||||
WeasyPrint is an extremely powerful and flexible reporting library. Refer to the [WeasyPrint docs](https://doc.courtbouillon.org/weasyprint/stable/) for further information.
|
||||
|
||||
### Stylesheets
|
||||
|
||||
Templates are rendered using standard HTML / CSS - if you are familiar with web page layout, you're ready to go!
|
||||
|
||||
### Template Language
|
||||
|
||||
Uploaded report template files are passed through the [django template rendering framework]({% include "django.html" %}/topics/templates/), and as such accept the same variable template strings as any other django template file. Different variables are passed to the report template (based on the context of the report) and can be used to customize the contents of the generated PDF.
|
||||
|
||||
### Context Variables
|
||||
|
||||
!!! info "Context Variables"
|
||||
Templates will have different variables available to them depending on the report type. Read the detailed information on each available report type for further information.
|
||||
|
||||
Please refer to the [Context variables](./context_variables.md) page.
|
||||
|
||||
|
||||
### Conditional Rendering
|
||||
|
||||
The django template system allows for conditional rendering, providing conditional flow statements such as:
|
||||
|
||||
```
|
||||
{% raw %}
|
||||
{% if <condition> %}
|
||||
{% do_something %}
|
||||
{% elif <other_condition> %}
|
||||
<!-- something else -->
|
||||
{% else %}
|
||||
<!-- finally -->
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
```
|
||||
{% raw %}
|
||||
{% for <item> in <list> %}
|
||||
Item: {{ item }}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! info "Conditionals"
|
||||
Refer to the [django template language documentation]({% include "django.html" %}/ref/templates/language/) for more information.
|
||||
|
||||
### Localization Issues
|
||||
|
||||
Depending on your localization scheme, inputting raw numbers into the formatting section template can cause some unintended issues. Consider the block below which specifies the page size for a rendered template:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: {{ width }}mm {{ height }}mm;
|
||||
margin: 0mm;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
If localization settings on the InvenTree server use a comma (`,`) character as a decimal separator, this may produce an output like:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% endraw %}
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: 57,3mm 99,0mm;
|
||||
margin: 0mm;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
```
|
||||
|
||||
The resulting `{% raw %}<style>{% endraw %}` CSS block will be *invalid*!
|
||||
|
||||
So, if you are writing a template which has custom formatting, (or any other sections which cannot handle comma decimal separators) you must wrap that section in a `{% raw %}{% localize off %}{% endraw %}` block:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% load l10n %}
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
{% localize off %}
|
||||
size: {{ width }}mm {{ height }}mm;
|
||||
{% endlocalize %}
|
||||
margin: 0mm;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! tip "Close it out"
|
||||
Don't forget to end with a `{% raw %}{% endlocalize %}{% endraw %}` tag!
|
||||
|
||||
!!! tip "l10n"
|
||||
You will need to add `{% raw %}{% load l10n %}{% endraw %}` to the top of your template file to use the `{% raw %}{% localize %}{% endraw %}` tag.
|
@ -171,4 +171,4 @@ The packages are provided by [packager.io](https://packager.io/). They are built
|
||||
|
||||
The package sets up [services](#controlling-inventree) that run the needed processes as the unprivileged user `inventree`. This keeps the privileges of InvenTree as low as possible.
|
||||
|
||||
A CLI is provided to interface with low-level management functions like [variable management](#enviroment-variables), log access, commands, process scaling, etc.
|
||||
A CLI is provided to interface with low-level management functions like [variable management](#environment-variables), log access, commands, process scaling, etc.
|
||||
|
27
docs/main.py
27
docs/main.py
@ -1,6 +1,7 @@
|
||||
"""Main entry point for the documentation build process."""
|
||||
|
||||
import os
|
||||
import textwrap
|
||||
|
||||
|
||||
def define_env(env):
|
||||
@ -22,3 +23,29 @@ def define_env(env):
|
||||
assets.append(os.path.join(subdir, asset))
|
||||
|
||||
return assets
|
||||
|
||||
@env.macro
|
||||
def templatefile(filename):
|
||||
"""Include code for a provided template file."""
|
||||
here = os.path.dirname(__file__)
|
||||
template_dir = os.path.join(
|
||||
here, '..', 'src', 'backend', 'InvenTree', 'report', 'templates'
|
||||
)
|
||||
template_file = os.path.join(template_dir, filename)
|
||||
template_file = os.path.abspath(template_file)
|
||||
|
||||
basename = os.path.basename(filename)
|
||||
|
||||
if not os.path.exists(template_file):
|
||||
raise FileNotFoundError(f'Report template file {filename} does not exist.')
|
||||
|
||||
with open(template_file, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
data = f'??? abstract "Template: {basename}"\n\n'
|
||||
data += ' ```html\n'
|
||||
data += textwrap.indent(content, ' ')
|
||||
data += '\n\n'
|
||||
data += ' ```\n\n'
|
||||
|
||||
return data
|
||||
|
@ -135,25 +135,15 @@ nav:
|
||||
- Return Orders: order/return_order.md
|
||||
- Project Codes: order/project_codes.md
|
||||
- Report:
|
||||
- Templates: report/report.md
|
||||
- Templates: report/templates.md
|
||||
- Template Rendering: report/weasyprint.md
|
||||
- Template Editor: report/template_editor.md
|
||||
- Report Types:
|
||||
- Test Reports: report/test.md
|
||||
- Build Order: report/build.md
|
||||
- Purchase Order: report/purchase_order.md
|
||||
- Sales Order: report/sales_order.md
|
||||
- Return Order: report/return_order.md
|
||||
- BOM: report/bom.md
|
||||
- Stock Location: report/stock_location.md
|
||||
- Labels:
|
||||
- Custom Labels: report/labels.md
|
||||
- Part Labels: report/labels/part_labels.md
|
||||
- Stock Labels: report/labels/stock_labels.md
|
||||
- Location Labels: report/labels/location_labels.md
|
||||
- Build Labels: report/labels/build_labels.md
|
||||
- Reports: report/report.md
|
||||
- Labels: report/labels.md
|
||||
- Context Variables: report/context_variables.md
|
||||
- Helper Functions: report/helpers.md
|
||||
- Barcodes: report/barcodes.md
|
||||
- Context Variables: report/context_variables.md
|
||||
- Sample Templates: report/samples.md
|
||||
- Admin:
|
||||
- Global Settings: settings/global.md
|
||||
- User Settings: settings/user.md
|
||||
@ -241,6 +231,7 @@ plugins:
|
||||
on_config: "docs.docs.hooks:on_config"
|
||||
- macros:
|
||||
include_dir: docs/_includes
|
||||
module_name: main
|
||||
- mkdocstrings:
|
||||
default_handler: python
|
||||
handlers:
|
||||
@ -250,6 +241,8 @@ plugins:
|
||||
options:
|
||||
show_symbol_type_heading: true
|
||||
show_symbol_type_toc: true
|
||||
show_root_heading: false
|
||||
show_root_toc_entry: false
|
||||
|
||||
# Extensions
|
||||
markdown_extensions:
|
||||
|
@ -5,4 +5,4 @@ mkdocs-git-revision-date-localized-plugin>=1.1,<2.0
|
||||
mkdocs-simple-hooks>=0.1,<1.0
|
||||
mkdocs-include-markdown-plugin
|
||||
neoteroi-mkdocs
|
||||
mkdocstrings[python]>=0.24.0
|
||||
mkdocstrings[python]>=0.25.0
|
||||
|
Reference in New Issue
Block a user