2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

Documentation integration (#4653)

* Add documentation under docs/ directory

* Add CI workflow for mkdocs configuration checking

* Add documentation issue template

* update pip-tools?

* Update .gitignore files

* Fix .gitignore rules

* Improve release notes page

* remove references to old repo
This commit is contained in:
Oliver
2023-04-22 22:40:29 +10:00
committed by GitHub
parent 20f01e8741
commit 2ffd2354eb
487 changed files with 44875 additions and 12 deletions

View File

@ -0,0 +1,86 @@
---
title: Barcode Generation
---
## Barcode Generation
Both [report](./report.md) and [label](./labels.md) templates can render custom barcode data to in-line images.
!!! info "img"
Barcode data must be rendered inside an `<img>` tag.
Inside the template file (whether it be for printing a label or generating a custom report), the following code will need to be included at the top of the template file:
```html
{% raw %}
<!-- Load the barcode helper functions -->
{% load barcode %}
{% endraw %}
```
### 1D Barcode
!!! info "python-barcode"
One dimensional barcodes (e.g. Code128) are generated using the [python-barcode](https://pypi.org/project/python-barcode/) library.
To render a 1D barcode, use the `barcode` template tag, as shown in the example below:
```html
{% raw %}
<!-- Don't forget to load the barcode helper! -->
{% load barcode %}
<img class='custom_class' src='{% barcode "12345678" %}'>
{% endraw %}
```
The default barcode renderer will generate a barcode using [Code128](https://en.wikipedia.org/wiki/Code_128) rendering. However [other barcode formats](https://python-barcode.readthedocs.io/en/stable/supported-formats.html) are also supported:
```html
{% raw %}
{% load barcode %}
<img class='custom_class' src='{% barcode "12345678" barcode_class="Code39" %}>
{% endraw %}
```
You can also pass further [python-barcode](https://python-barcode.readthedocs.io/en/stable/writers.html#common-writer-options) supported parameters as well:
```html
{% raw %}
{% load barcode %}
<img class='barcode' src='{% barcode part.IPN barcode_class="Code128" write_text=0 background="red" %}'>
{% endraw %}
```
### QR-Code
!!! info "qrcode"
Two dimensional QR codes are generated using the [qrcode](https://pypi.org/project/qrcode/) library.
To render a QR code, use the `qrcode` template tag:
```html
{% raw %}
{% load barcode %}
<img class='custom_qr_class' src='{% qrcode "Hello world!" %}'>
{% endraw %}
```
Additional parameters can be passed to the `qrcode` function for rendering:
```html
{% raw %}
<img class='custom_qr_class' src='{% qrcode "Hello world!" fill_color="green" back_color="blue" %}'>
{% endraw %}
```
!!! tip "Documentation"
Refer to the [qrcode library documentation](https://pypi.org/project/qrcode/) for more information

186
docs/docs/report/bom.md Normal file
View File

@ -0,0 +1,186 @@
---
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}} - {{ date.isoformat }}";
{% 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/InvenTree/report/templates/report/inventree_bill_of_materials_report.html) for the default test report template.

299
docs/docs/report/build.md Normal file
View File

@ -0,0 +1,299 @@
---
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 |
| reference | The build order reference string |
| quantity | Build order quantity |
#### 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) |
| bom_items | A query set with all BOM items for the 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 |
| 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.
#### bom_items
| Variable | Description |
| --- | --- |
| .reference | The reference designators of the components |
| .quantity | The number of components |
| .sub_part | The part at this position |
| .substitutes.all | A query set with all allowed substitutes for that part |
#### allocated_stock.all
| Variable | 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}} - {{ date.isoformat }}";
{% 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>{% render_date build.creation_date %}</td>
</tr>
<tr>
<th>{% trans "Target Date" %}</th>
<td>
{% if build.target_date %}
{% render_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/InvenTree/report/templates/report/inventree_build_order_base.html) for the default build report template.

View File

@ -0,0 +1,256 @@
---
title: Context Variables
---
## Context Variables
### Report
!!! info "Specific Report Context"
Specific report types may have additional context variables, see below.
Each report has access to a number of context variables by default. The following context variables are provided to every report template:
| Variable | Description |
| --- | --- |
| date | Current date, represented as a Python datetime.date object |
| datetime | Current datetime, represented as a Python datetime object |
| default_page_size | InvenTree default page size variable |
| 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 |
| user | User who made the request to render the template |
#### Label
Certain types of labels have different context variables then other labels.
##### Stock Item Label
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 |
##### Stock Location Label
The following variables are made available to the StockLocation label template:
| Variable | Description |
| -------- | ----------- |
| location | The [StockLocation](./context_variables.md#stocklocation) object itself |
### 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:
| Variable | Description |
|----------|-------------|
| name | Brief name for this part |
| full_name | Full name for this part (including IPN, if not null and including variant, if not null) |
| variant | Optional variant number for this part - Must be unique for the part name
| category | The [PartCategory](./context_variables.md#part-category) object to which this part belongs
| description | Longer form description of the part
| keywords | Optional keywords for improving part search results
| IPN | Internal part number (optional)
| revision | Part revision
| is_template | If True, this part is a 'template' part
| link | Link to an external page with more information about this part (e.g. internal Wiki)
| image | Image of this part
| default_location | The default [StockLocation](./context_variables.md#stocklocation) object where the item is normally stored (may be null)
| default_supplier | The default [SupplierPart](./context_variables.md#supplierpart) which should be used to procure and stock this part
| default_expiry | The default expiry duration for any StockItem instances of this part
| minimum_stock | Minimum preferred quantity to keep in stock
| units | Units of measure for this part (default='pcs')
| salable | Can this part be sold to customers?
| assembly | Can this part be build from other parts?
| component | Can this part be used to make other parts?
| purchaseable | Can this part be purchased from suppliers?
| trackable | Trackable parts can have unique serial numbers assigned, etc, etc
| active | Is this part active? Parts are deactivated instead of being deleted
| virtual | Is this part "virtual"? e.g. a software product or similar
| notes | Additional notes field for this part
| creation_date | Date that this part was added to the database
| creation_user | User who added this part to the database
| responsible | User who is responsible for this part (optional)
| starred | Wether the part is starred or not |
| disabled | Wether the part is disabled or not |
| total_stock | The total amount in stock |
| quantity_being_built | The amount being built |
| required_build_order_quantity | The amount required for build orders |
| allocated_build_order_quantity | The amount allocated for build orders |
| build_order_allocations | Query set with all build order allocations for that part |
| required_sales_order_quantity | The amount required for sales orders |
| allocated_sales_order_quantity | The amount allocated for sales orders |
| available | Wether the part is available or not |
| on_order | The amount that are on order |
| required | The total amount required for build orders and sales orders |
| allocated | The total amount allocated for build orders and sales orders |
#### Part Category
| Variable | Description |
|----------|-------------|
| name | Name of this category |
| parent | Parent category |
| default_location | Default [StockLocation](./context_variables.md#stocklocation) object for parts in this category or child categories |
| default_keywords | Default keywords for parts created in this category |
### Stock
#### Stock Item
| Variable | Description |
|----------|-------------|
| parent | Link to another [StockItem](./context_variables.md#stockitem) from which this StockItem was created |
| uid | Field containing a unique-id which is mapped to a third-party identifier (e.g. a barcode) |
| part | Link to the master abstract [Part](./context_variables.md#part) that this [StockItem](./context_variables.md#stockitem) is an instance of |
| supplier_part | Link to a specific [SupplierPart](./context_variables.md#supplierpart) (optional) |
| location | The [StockLocation](./context_variables.md#stocklocation) Where this [StockItem](./context_variables.md#stockitem) is located |
| quantity | Number of stocked units |
| batch | Batch number for this [StockItem](./context_variables.md#stockitem) |
| serial | Unique serial number for this [StockItem](./context_variables.md#stockitem) |
| link | Optional URL to link to external resource |
| updated | Date that this stock item was last updated (auto) |
| expiry_date | Expiry date of the [StockItem](./context_variables.md#stockitem) (optional) |
| stocktake_date | Date of last stocktake for this item |
| stocktake_user | User that performed the most recent stocktake |
| review_needed | Flag if [StockItem](./context_variables.md#stockitem) needs review |
| delete_on_deplete | If True, [StockItem](./context_variables.md#stockitem) will be deleted when the stock level gets to zero |
| status | Status of this [StockItem](./context_variables.md#stockitem) (ref: InvenTree.status_codes.StockStatus) |
| 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) |
| 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) |
| packaging | Description of how the StockItem is packaged (e.g. "reel", "loose", "tape" etc) |
#### Stock Location
| Variable | Description |
|----------|-------------|
| barcode | Brief payload data (e.g. for labels). Example: {"stocklocation": 826} where 826 is the primary key|
| description | The description of the location |
| icon | The name of the icon if set, e.g. fas fa-warehouse |
| item_count | Simply returns the number of stock items in this location |
| name | The name of the location. This is only the name of this location, not the path |
| owner | The owner of the location if it has one. The owner can only be assigned in the admin interface |
| parent | The parent location. Returns None if it is already the top most one |
| path | A queryset of locations that contains the hierarchy starting from the top most parent |
| path_string | A string that contains all names of the path separated by slashes e.g. A/B/C |
| structural | True if the location is structural |
### Suppliers
#### Supplier
| Variable | Description |
|----------|-------------|
| name | Name of the company |
| description | Longer form description |
| website | URL for the company website |
| address | Postal address |
| contact | Contace Name |
| phone | Contact phone number |
| email | Contact email address |
| link | A second econdary URL to the company (Actually only accessible in the admin interface) |
| notes | Extra notes about the company (Actually only accessible in the admin interface) |
| is_customer | Boolean value, is this company a customer |
| is_supplier | Boolean value, is this company a supplier |
| is_manufacturer | Boolean value, is this company a manufacturer |
| currency_code | Default currency for the company |
| parts | Query set with all parts that the company supplies |
#### SupplierPart
| Variable | Description |
|----------|-------------|
| part | Link to the master Part (Obsolete) |
| source_item | The sourcing [StockItem](./context_variables.md#stockitem) linked to this [SupplierPart](./context_variables.md#supplierpart) instance |
| supplier | [Supplier](./context_variables.md#supplier) that supplies this part |
| SKU | Stock keeping unit (supplier part number) |
| link | Link to external website for this supplier part |
| description | Descriptive notes field |
| note | Longer form note field |
| base_cost | Base charge added to order independent of quantity e.g. "Reeling Fee" |
| multiple | Multiple that the part is provided in |
| lead_time | Supplier lead time |
| packaging | packaging that the part is supplied in, e.g. "Reel" |
| pretty_name | The IPN, supplier name, supplier SKU and (if not null) manufacturer string joined by `|`. Ex. `P00037 | Company | 000021` |
| unit_pricing | The price for one unit. |
| price_breaks | Return the associated price breaks in the correct order |
| has_price_breaks | Wether 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
!!! incomplete "TODO"
This section requires further work
The [Purchase Order](../buy/po.md) context variables are described in the [Purchase Order](purchase_order.md) section.
#### SalesOrder
A [Sales Order](../sell/so.md) object has the following context variables available.
| Variable | Description |
|----------|-------------|
| customer | An object with information about the customer |
| description | The order description |
| lines | The lines in the Sales Order |
| reference | The reference number |
#### Return Order
A [Return Order](../sell/return.md) object has the following context variables avaiable.
| Variable | Description |
| --- | --- |
| customer | An object with information about the customer |
| description | The order description |
| lines | The lines in the Sales Order |
| reference | The reference number |
### User
| Variable | Description |
|----------|-------------|
| username | the username of the user |
| fist_name | The first name of the user |
| last_name | The last name of the user |
| email | The email address of the user |
| pk | The primary key of the user |

151
docs/docs/report/helpers.md Normal file
View File

@ -0,0 +1,151 @@
---
title: Helper Functions
---
Some common functions are provided for use in custom report and label templates. To include these, load the `report` functions at the start of the template:
```html
{% raw %}
<!-- Load the report helper functions -->
{% load report %}
{% endraw %}
```
!!! tip "Use the Source, Luke"
To see the full range of available helper functions, refer to the source file [report.py](https://github.com/inventree/InvenTree/blob/master/InvenTree/report/templatetags/report.py) where these functions are defined!
## Rendering Currency
The helper function `render_currency` allows for simple rendering of currency data. This function can also convert the specified amount of currency into a different target currency:
```html
{% raw %}
{% load report %}
<em>Line Item Unit Pricing:</em>
<ul>
{% for line in order.lines %}
<li>{% render_currency line.price currency=order.supplier.currency %}</li>
{% endfor %}
</ul>
Total Price: {% render_currency order.total_price currency='NZD' decimal_places=2 %}
{% endraw %}
```
## Maths Operations
Simple mathematical operators are available, as demonstrated in the example template below:
```html
{% raw %}
<!-- Load the report helper functions -->
{% load report %}
{% add 1 3 %} <!-- Add two numbers together -->
{% subtract 4 3 %} <!-- Subtract 3 from 4 -->
{% multiply 1.2 3.4 %} <!-- Multiply two numbers -->
{% divide 10 2 %} <!-- Divide 10 by 2 -->
{% endraw %}
```
These operators can also be used with variables:
```html
{% raw %}
{% load report %}
{% for line in order.lines %}
Total: {% multiply line.purchase_price line.quantity %}<br>
{% endfor %}
{% endraw %}
```
## Media Files
*Media files* are any files uploaded to the InvenTree server by the user. These are stored under the `/media/` directory and can be accessed for use in custom reports or labels.
### Uploaded Images
You can access an uploaded image file if you know the *path* of the image, relative to the top-level `/media/` directory. To load the image into a report, use the `{% raw %}{% uploaded_image ... %}{% endraw %}` tag:
```html
{% raw %}
<!-- Load the report helper functions -->
{% load report %}
<img src='{% uploaded_image "subdir/my_image.png" %}'/>
{% endraw %}
```
!!! info "Missing Image"
If the supplied image filename does not exist, it will be replaced with a placeholder image file
!!! warning "Invalid Image"
If the supplied file is not a valid image, it will be replaced with a placeholder image file
### Part images
A shortcut function is provided for rendering an image associated with a Part instance. You can render the image of the part using the `{% raw %}{% part_image ... %}{% endraw %}` template tag:
```html
{% raw %}
<!-- Load the report helper functions -->
{% load report %}
<img src='{% part_image part %}'/>
{% endraw %}
```
### Company Images
A shortcut function is provided for rendering an image associated with a Company instance. You can render the image of the company using the `{% raw %}{% company_image ... %}{% endraw %}` template tag:
```html
{% raw %}
<!-- Load the report helper functions -->
{% load report %}
<img src='{% company_image company %}'/>
{% endraw %}
```
## InvenTree Logo
A template tag is provided to load the InvenTree logo image into a report. You can render the logo using the `{% raw %}{% logo_image %}{% endraw %}` tag:
```html
{% raw %}
{% load report %}
<img src='{% logo_image %}'/>
{% endraw %}
```
### 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.
This is a useful way to get a custom company logo into your reports.
If you have a custom logo, but explicitly wish to load the InvenTree logo itself, add `custom=False` to the tag:
```html
{% raw %}
{% load report %}
<img src='{% logo_image custom=False %}'/>
{% endraw %}
```
## Report Assets
[Report Assets](./report.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:
```html
{% raw %}
<!-- Load the report helper functions -->
{% load report %}
<img src="{% asset 'my_awesome_logo.png' %}"/>
{% endraw %}
```

312
docs/docs/report/labels.md Normal file
View File

@ -0,0 +1,312 @@
---
title: Custom Labels
---
## Custom Labels
InvenTree supports printing of custom template-based labels, using the [WeasyPrint](https://weasyprint.org/) PDF generation engine.
Custom labels can be generated using simple HTML templates, with support for QR-codes, and conditional formatting using the Django template engine.
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 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.
A label template is a single `.html` file which is uploaded to the InvenTree server by the user.
Below is a reasonably simple example of a label template which demostrates much of the available functionality. The template code shown below will produce the following label:
{% with id="label_example", url="report/label_example.png", description="Example label" %}
{% include 'img.html' %}
{% endwith %}
```html
{% raw %}
<style>
@page {
width: 75mm;
height: 24mm;
padding: 1mm;
margin: 0px 0px 0px 0px;
}
.location {
padding: 5px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
height: 100%;
vertical-align: middle;
float: right;
display: inline;
font-size: 125%;
position: absolute;
top: 0mm;
left: 23mm;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.qr {
margin: 2px;
width: 22mm;
height: 22mm;
}
</style>
{% load barcode %}
<img class='qr' src="{% qrcode location.format_barcode %}"/>
<div class='location'>
{{ location.name }}
<br>
<br>
<hr>
Location ID: {{ location.id }}
</div>
</div>
{% endraw %}
```
Each significant component of the example template above are described in the sections below:
### Stylesheet
The stylesheet defines the *style* of the label, and is enclosed within the `<style>...</style>` tags. The stylesheet supports any of the CSS features which are supported natively by weasyprint.
Some points of note:
- The `@page` directive specifies the size of the label, and global margins.
- Normal per-class and per-element styling is supported
- Absolute positioning of elements is supported via the `position` CSS directive
- If text is too long to fit on a given label, the `text-overflow` directive can be used
### Context Data
Each label template is supplied with *context data* (variables) which can be used to display information based on the context in which the label is printed. Variables supplied as context objects can be easily rendered to the label using Django templating syntax.
For example, if a StockLocation object is supplied to the label as the variable `location`, it is trivially simple to render the data to the label:
```html
{% raw %}
Location ID: {{ location.id }}
<br>
Location Name: {{ location.name }}
{% endraw %}
```
Refer to the [context variables documentation](./context_variables.md).
### Barcodes
Refer to the [barcode documentation](./barcodes.md).
### Using media files
Refer to the [media files documentation](./helpers.md#media-files).
### Conditional Formatting
Conditional formatting of label data is also supported. Below is an example excerpt from a label which determines the content based on the supplied context variables:
```html
{% raw %}
{% if item.in_stock %}
Quantity: {{ item.quantity }}
{% else %}
OUT OF STOCK
{% endif %}
{% endraw %}
```
### Label Filters
Each label template provides a set of programmable filters which can be used to determine the relevance of that particular label. It may be the case that a particular label template is only applicable if certain conditions are met.
As an example, consider a label template for a StockItem. A user may wish to define a label which displays the firmware version of any items related to the Part with the IPN (Internal Part Number) `IPN123`.
To restrict the label accordingly, we could set the *filters* value to `part__IPN=IPN123`.
## Built-In Templates
The InvenTree installation provides a number of simple *default* templates which can be used as a starting point for creating custom labels. These built-in templates can be disabled if they are not required.
Built-in templates can also be used to quickly scaffold custom labels, using template inheritance.
### Base Template
For example, InvenTree provides a *base* template from which all of the default label templates are derived. This *base* template provides the essentials for generating a label:
```html
{% raw %}
<head>
<style>
@page {
size: {{ width }}mm {{ height }}mm;
{% block margin %}
margin: 0mm;
{% endblock %}
}
img {
display: inline-block;
image-rendering: pixelated;
}
{% block style %}
{% endblock %}
</style>
</head>
<body>
{% block content %}
<!-- Label data rendered here! -->
{% endblock %}
</body>
{% endraw %}
```
### Extend Base Template
To extend this template in a custom uploaded label, simply extend as follows:
```html
{% raw %}
{% extends "label/label_base.html" %}
{% block style %}
<!-- You can write custom CSS here -->
{% endblock %}
{% block content %}
<!-- HTML content goes here! -->
{% endblock %}
{% endraw %}
```
## 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.
## 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 |
## 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 |
#### Parameters
The part parameters can be accessed by parameter name lookup in the template, as follows:
```html
{% raw %}
Part: {{ part.name }}
Length: {{ parameters.length }}
{% endraw %}
```

View File

@ -0,0 +1,50 @@
---
title: Purchase Order Report
---
## Purchase Order Reports
Custom purchase order reports may be generated against any given [Purchase Order](../buy/po.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](../buy/po.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](../buy/supplier.md) 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 |
#### Lines
The lines have sub variables.
| Variable | Description |
| --- | --- |
| quantity | The quantity of the part to be ordered |
| part | The supplier part to be ordered |
| part | The [supplierpart ](./context_variables.md#supplierpart) object that the build references |
| 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 price the part supplierpart |
| destination | The stock location where the part will be stored |
### 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/InvenTree/report/templates/report/inventree_po_report_base.html) for the default purchase order report template.

321
docs/docs/report/report.md Normal file
View File

@ -0,0 +1,321 @@
---
title: Report Generation
---
## Custom Reporting
InvenTree supports a customizable reporting ecosystem, allowing the user to develop reporting templates that meet their particular needs.
PDF reports 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.
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.
### WeasyPrint Templates
InvenTree report templates utilize the powerful [WeasyPrint](https://weasyprint.org/) PDF generation engine.
!!! info "WeasyPrint"
WeasyPrint is an extremely powerful and flexible reporting library. Refer to the [WeasyPrint docs](https://weasyprint.readthedocs.io/en/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](https://docs.djangoproject.com/en/dev/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.
### Variables
Each report template is provided a set of *context variables* which can be used when rendering the template.
For example, rendering the name of a part (which is available in the particular template context as `part`) is as follows:
```html
{% raw %}
<!-- Template variables use {{ double_curly_braces }} -->
<h2>Part: {{ part.name }}</h3>
<p><i>
Description:<br>
{{ part.description }}
</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](https://docs.djangoproject.com/en/dev/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 %}
<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!
### 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 |
### 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/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 overrie 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"
### 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/docker_dev.md/#data-directory). 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 %}
```

View File

@ -0,0 +1,26 @@
---
title: Return Order Reports
---
## Return Order Reports
Custom reports may be generated against any given [Return Order](../sell/return.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/InvenTree/report/templates/report/inventree_return_order_report_base.html) for the default return order report template.

View File

@ -0,0 +1,30 @@
---
title: Sales Order Reports
---
## Sales Order Reports
Custom sales order reports may be generated against any given [Sales Order](../sell/so.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](../sell/so.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](../sell/customer.md) 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 |
### 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/InvenTree/report/templates/report/inventree_so_report_base.html) for the default sales order report template.

87
docs/docs/report/test.md Normal file
View File

@ -0,0 +1,87 @@
---
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/InvenTree/report/templates/report/inventree_test_report_base.html) for the default test report template.