* Adds decorator to mark an attribute for report context discovery * Update context variables in docs * Include fields captured against each model type * Expose more properties * Image URL tags * Add more attributes * Rearrange docs * Simplify docs * Enforce type hinting for reportable properties * Expose more properties for the Order model * Auto-discover related / linked models * Remove extra text * Collapsible blocks * Reduce boilerplate * Remove cruft * Enhance documentation for filename generation * Cleanup
6.9 KiB
title
| title |
|---|
| Report Context |
Report Context Variables
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.
Global Context
In addition to the model-specific context variables, the following global context variables are available to all templates:
{{ report_context("base", "global") }}
Report Context
In addition to the global context, all report templates have access to the following context variables:
{{ report_context("base", "report") }}
When using the merge context variable, the selected items are available in the instances list. To access individual item attributes, you can either loop through the instances or access them by index like instance.0.name.
Below is an example template that generates a single report for some selected parts. Each part occupies a row in the table
{% raw %}
<h2>Merged Report for Selected Parts</h2>
<table>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
{% for part in instances %}
<tr>
<td>{{ part.name }}</td>
<td>{{ part.description }}</td>
</tr>
{% endfor %}
</table>
{% endraw %}
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, all label templates have access to the following context variables:
{{ report_context("base", "label") }}
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 or labels) are rendered against a particular "model" type. The following model types are supported, and can have templates renderer against them:
| Model Type | Description |
|---|---|
| company | A Company instance |
| build | A Build Order instance |
| buildline | A Build Order Line Item instance |
| salesorder | A Sales Order instance |
| salesordershipment | A Sales Order Shipment instance |
| returnorder | A Return Order instance |
| purchaseorder | A Purchase Order instance |
| transferorder | A Transfer Order instance |
| stockitem | A StockItem instance |
| stocklocation | A StockLocation instance |
| part | A Part instance |
Company
When printing a report or label against a Company instance, the following context variables are available:
{{ report_context("models", "company") }}
For the fields and properties available on the underlying Company instance, refer to the Model Context page.
Build Order
When printing a report or label against a Build Order object, the following context variables are available:
{{ report_context("models", "build") }}
For the fields and properties available on the underlying Build instance, refer to the Model Context page.
Build Line
When printing a report or label against a BuildOrderLineItem object, the following context variables are available:
{{ report_context("models", "buildline") }}
For the fields and properties available on the underlying BuildLine instance, refer to the Model Context page.
Sales Order
When printing a report or label against a SalesOrder object, the following context variables are available:
{{ report_context("models", "salesorder") }}
For the fields and properties available on the underlying SalesOrder instance, refer to the Model Context page.
Sales Order Shipment
When printing a report or label against a SalesOrderShipment object, the following context variables are available:
{{ report_context("models", "salesordershipment") }}
For the fields and properties available on the underlying SalesOrderShipment instance, refer to the Model Context page.
Return Order
When printing a report or label against a ReturnOrder object, the following context variables are available:
{{ report_context("models", "returnorder") }}
For the fields and properties available on the underlying ReturnOrder instance, refer to the Model Context page.
Purchase Order
When printing a report or label against a PurchaseOrder object, the following context variables are available:
{{ report_context("models", "purchaseorder") }}
For the fields and properties available on the underlying PurchaseOrder instance, refer to the Model Context page.
Transfer Order
When printing a report or label against a TransferOrder object, the following context variables are available:
{{ report_context("models", "transferorder") }}
For the fields and properties available on the underlying TransferOrder instance, refer to the Model Context page.
Stock Item
When printing a report or label against a StockItem object, the following context variables are available:
{{ report_context("models", "stockitem") }}
For the fields and properties available on the underlying StockItem instance, refer to the Model Context page.
Stock Location
When printing a report or label against a StockLocation object, the following context variables are available:
{{ report_context("models", "stocklocation") }}
For the fields and properties available on the underlying StockLocation instance, refer to the Model Context page.
Part
When printing a report or label against a Part object, the following context variables are available:
{{ report_context("models", "part") }}
For the fields and properties available on the underlying Part instance, refer to the Model Context page.
Model Context
For the underlying fields and properties available on each of the model instances above (plus related model types such as Address or SupplierPart), refer to the Model Context page.