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:
| Variable | Type | Description |
|---|---|---|
| base_url | str |
The base URL for the InvenTree instance |
| date | datetime.date |
Current date, represented as a Python datetime.date object |
| datetime | datetime.datetime |
Current datetime, represented as a Python datetime object |
| template | report.models.ReportTemplateBase |
The report template instance which is being rendered against |
| template_description | str |
Description of the report template |
| template_name | str |
Name of the report template |
| template_revision | int |
Revision of the report template |
| user | typing.Union[django.contrib.auth.models.AbstractUser, None] |
User who is creating the report (if available) |
Report Context¶
In addition to the global context, all report templates have access to the following context variables:
| Variable | Type | Description |
|---|---|---|
| page_size | str |
The page size of the report |
| landscape | bool |
Boolean value, True if the report is in landscape mode |
| merge | bool |
Boolean value, True if the a single report is generated against multiple items |
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
<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>
Note that custom plugins may also add additional context variables to the report context.
Supply context data to the report template for rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Model
|
The model instance we are printing against |
required |
Source code in src/backend/InvenTree/report/models.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
Label Context¶
In addition to the global context, all label templates have access to the following context variables:
| Variable | Type | Description |
|---|---|---|
| width | float |
The width of the label (in mm) |
| height | float |
The height of the label (in mm) |
| page_style | typing.Union[str, None] |
The CSS @page style for the label template. This is used to be inserted at the top of the style block for a given label |
Note that custom plugins may also add additional context variables to the label context.
Supply context data to the label template for rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Model
|
The model instance we are printing against |
required |
Source code in src/backend/InvenTree/report/models.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
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:
| Variable | Type | Description |
|---|---|---|
| company | company.models.Company |
The Company object associated with this context |
| name | str |
The name of the Company |
| description | str |
A description of the Company |
| website | str |
The website URL for the Company |
| phone | str |
The contact phone number for the Company |
str |
The contact email address for the Company | |
| address | str |
The primary address associated with the 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:
| Variable | Type | Description |
|---|---|---|
| bom_items | QuerySet[part.models.BomItem] |
Query set of all BuildItem objects associated with the BuildOrder |
| build | build.models.Build |
The BuildOrder instance itself |
| build_outputs | QuerySet[stock.models.StockItem] |
Query set of all BuildItem objects associated with the BuildOrder |
| line_items | QuerySet[build.models.BuildLine] |
Query set of all build line items associated with the BuildOrder |
| part | part.models.Part |
The Part object which is being assembled in the build order |
| quantity | int |
The total quantity of the part being assembled |
| reference | str |
The reference field of the BuildOrder |
| title | str |
The title field of the BuildOrder |
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:
| Variable | Type | Description |
|---|---|---|
| allocated_quantity | decimal.Decimal |
The quantity of the part which has been allocated to this build |
| allocations | QuerySet[build.models.BuildItem] |
A query set of all StockItem objects which have been allocated to this build line |
| bom_item | part.models.BomItem |
The BomItem associated with this line item |
| build | build.models.Build |
The BuildOrder instance associated with this line item |
| build_line | build.models.BuildLine |
The build line instance itself |
| part | part.models.Part |
The sub-part (component) associated with the linked BomItem instance |
| quantity | decimal.Decimal |
The quantity required for this line item |
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:
| Variable | Type | Description |
|---|---|---|
| description | str |
The description field of the SalesOrder |
| reference | str |
The reference field of the SalesOrder |
| title | str |
The title (string representation) of the SalesOrder |
| extra_lines | QuerySet[order.models.SalesOrderExtraLine] |
Query set of all extra lines associated with the SalesOrder |
| lines | QuerySet[order.models.SalesOrderLineItem] |
Query set of all line items associated with the SalesOrder |
| order | order.models.SalesOrder |
The SalesOrder instance itself |
| customer | typing.Union[company.models.Company, None] |
The customer object associated with the 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:
| Variable | Type | Description |
|---|---|---|
| allocations | QuerySet[order.models.SalesOrderAllocation] |
QuerySet of SalesOrderAllocation objects |
| order | order.models.SalesOrder |
The associated SalesOrder object |
| reference | str |
Shipment reference string |
| address | company.models.Address |
The shipping address for this shipment (or order) |
| shipment | order.models.SalesOrderShipment |
The SalesOrderShipment object itself |
| tracking_number | str |
Shipment tracking number string |
| title | str |
Title for the report |
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:
| Variable | Type | Description |
|---|---|---|
| description | str |
The description field of the ReturnOrder |
| reference | str |
The reference field of the ReturnOrder |
| title | str |
The title (string representation) of the ReturnOrder |
| extra_lines | QuerySet[order.models.ReturnOrderExtraLine] |
Query set of all extra lines associated with the ReturnOrder |
| lines | QuerySet[order.models.ReturnOrderLineItem] |
Query set of all line items associated with the ReturnOrder |
| order | order.models.ReturnOrder |
The ReturnOrder instance itself |
| customer | typing.Union[company.models.Company, None] |
The customer object associated with the 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:
| Variable | Type | Description |
|---|---|---|
| description | str |
The description field of the PurchaseOrder |
| reference | str |
The reference field of the PurchaseOrder |
| title | str |
The title (string representation) of the PurchaseOrder |
| extra_lines | QuerySet[order.models.PurchaseOrderExtraLine] |
Query set of all extra lines associated with the PurchaseOrder |
| lines | QuerySet[order.models.PurchaseOrderLineItem] |
Query set of all line items associated with the PurchaseOrder |
| order | order.models.PurchaseOrder |
The PurchaseOrder instance itself |
| supplier | typing.Union[company.models.Company, None] |
The supplier object associated with the 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:
| Variable | Type | Description |
|---|---|---|
| description | str |
The description field of the TransferOrder |
| extra_lines | typing.Any |
|
| lines | QuerySet[order.models.TransferOrderLineItem] |
Query set of all line items associated with the TransferOrder |
| order | order.models.TransferOrder |
The TransferOrder instance itself |
| reference | str |
The reference field of the TransferOrder |
| title | str |
The title (string representation) of the TransferOrder |
| take_from | stock.models.StockLocation |
|
| destination | stock.models.StockLocation |
|
| consume | bool |
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:
| Variable | Type | Description |
|---|---|---|
| barcode_data | str |
Generated barcode data for the StockItem |
| barcode_hash | str |
Hash of the barcode data |
| batch | str |
The batch code for the StockItem |
| child_items | QuerySet[stock.models.StockItem] |
Query set of all StockItem objects which are children of this StockItem |
| ipn | types.UnionType[str, None] |
The IPN (internal part number) of the associated Part |
| installed_items | set[stock.models.StockItem] |
Query set of all StockItem objects which are installed in this StockItem |
| item | stock.models.StockItem |
The StockItem object itself |
| name | str |
The name of the associated Part |
| part | part.models.Part |
The Part object which is associated with the StockItem |
| qr_data | str |
Generated QR code data for the StockItem |
| qr_url | str |
Generated URL for embedding in a QR code |
| parameters | dict[str, str] |
Dict object containing the parameters associated with the base Part |
| quantity | decimal.Decimal |
The quantity of the StockItem |
| result_list | list[stock.models.StockItemTestResult] |
FLattened list of TestResult data associated with the stock item |
| results | dict[str, stock.models.StockItemTestResult] |
Dict object of TestResult data associated with the StockItem |
| serial | types.UnionType[str, None] |
The serial number of the StockItem |
| stock_item | stock.models.StockItem |
The StockItem object itself (shadow of 'item') |
| tests | dict[str, stock.models.StockItemTestResult] |
Dict object of TestResult data associated with the StockItem (shadow of 'results') |
| test_keys | list[str] |
List of test keys associated with the StockItem |
| test_template_list | QuerySet[part.models.PartTestTemplate] |
List of test templates associated with the StockItem |
| test_templates | dict[str, part.models.PartTestTemplate] |
Dict object of test templates associated with the 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:
| Variable | Type | Description |
|---|---|---|
| location | stock.models.StockLocation |
The StockLocation object itself |
| qr_data | str |
Formatted QR code data for the StockLocation |
| parent | types.UnionType[stock.models.StockLocation, None] |
The parent StockLocation object |
| stock_location | stock.models.StockLocation |
The StockLocation object itself (shadow of 'location') |
| stock_items | QuerySet[stock.models.StockItem] |
Query set of all StockItem objects which are located in the 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:
| Variable | Type | Description |
|---|---|---|
| bom_items | QuerySet[part.models.BomItem] |
Query set of all BomItem objects associated with the Part |
| category | types.UnionType[part.models.PartCategory, None] |
The PartCategory object associated with the Part |
| description | str |
The description field of the Part |
| IPN | types.UnionType[str, None] |
The IPN (internal part number) of the Part |
| name | str |
The name of the Part |
| parameters | dict[str, str] |
Dict object containing the parameters associated with the Part |
| part | part.models.Part |
The Part object itself |
| qr_data | str |
Formatted QR code data for the Part |
| qr_url | str |
Generated URL for embedding in a QR code |
| revision | types.UnionType[str, None] |
The revision of the Part |
| test_template_list | QuerySet[part.models.PartTestTemplate] |
List of test templates associated with the Part |
| test_templates | dict[str, part.models.PartTestTemplate] |
Dict object of test templates associated with the 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.