mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-27 21:26:43 +00:00
Report section and python API reference (#400)
* started python API reference guide * Added test to the API reference guide * Added Price break * added context variables to the build section * Cleand up build section and added new example * Fine tuning * fixed picture * removed unfinished python reference guide
This commit is contained in:
parent
94d0bc8e63
commit
228828bd42
BIN
docs/assets/images/build/report-61.png
Normal file
BIN
docs/assets/images/build/report-61.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -17,91 +17,268 @@ In addition to the default report context variables, the following context varia
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| build | The [Build](./context_variables.md#build) object the report is being generated against |
|
||||
| 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. This is just the string that follows BO... |
|
||||
| title | The full name of the build including the BO |
|
||||
| reference | The build order reference string |
|
||||
| quantity | Build order quantity |
|
||||
| build.title | The description of the build |
|
||||
| build.status | The status of the build. 20 means 'Production' |
|
||||
| build.bom_items | A query set with all bom items for the build |
|
||||
|
||||
bom_items that can be looped. Each bom_item line has further context variables.
|
||||
#### build
|
||||
|
||||
The following variables are accessed by build.variable
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| line.reference | The reference designator of the component |
|
||||
| line.sub_part | The part at this position |
|
||||
| line.quantity | The number of components |
|
||||
| line.sub_part.build_order_allocations | ... |
|
||||
| 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 ( all material allocated)|
|
||||
| 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 | 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 | 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 | User (or group) responsible for completing the build |
|
||||
| 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 |
|
||||
| title | The description of the build |
|
||||
|
||||
A very simple example wihtout any html formatting:
|
||||
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 |
|
||||
|
||||
### Example
|
||||
|
||||
The following example will create a report with header and BOM. In the BOM table substitutes will be listed.
|
||||
|
||||
{% raw %}
|
||||
```html
|
||||
reference: {{reference }}
|
||||
<br>
|
||||
quantity: {{ quantity }}
|
||||
<br>
|
||||
title: {{ title }}
|
||||
<br>
|
||||
part: {{ part }}
|
||||
<br>
|
||||
build: {{ build }}
|
||||
<br>
|
||||
<br>
|
||||
build.reference: {{ build.reference }}
|
||||
<br>
|
||||
build.title: {{ build.title }}
|
||||
<br>
|
||||
build.status: {{ build.status }}
|
||||
<br>
|
||||
-------
|
||||
<br>
|
||||
{% for line in build.bom_items %}
|
||||
reference:: {{ line.reference }}
|
||||
<br>
|
||||
quantity:: {{ line.quantity }}
|
||||
<br>
|
||||
sub_part: {{ line.sub_part }}
|
||||
<br>
|
||||
sub_part.IPN: {{ line.sub_part.IPN }}
|
||||
<br>
|
||||
sub_part.name: {{ line.sub_part.name }}
|
||||
<br>
|
||||
sub_part.build_order_allocations: {{ line.sub_part.build_order_allocations }}
|
||||
<br>
|
||||
........
|
||||
<br>
|
||||
{% endfor %}
|
||||
{% 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 %}
|
||||
```
|
||||
|
||||
This will result in:
|
||||
|
||||
```text
|
||||
reference: 0001
|
||||
quantity: 10
|
||||
title: BO0001
|
||||
part: POP-000001-001 | Converter - A to B
|
||||
build: BO0001
|
||||
|
||||
build.reference: 0001
|
||||
build.title: Description of the build
|
||||
build.status: 20
|
||||
-------
|
||||
reference:: U002
|
||||
quantity:: 1.00000
|
||||
sub_part: ANA-000001-001 | op701 - operation amplifier
|
||||
sub_part.IPN: ANA-000001-001
|
||||
sub_part.name: op701
|
||||
sub_part.build_order_allocations: <QuerySet [<BuildItem: BuildItem object (9)>]>
|
||||
........
|
||||
reference:: U001
|
||||
quantity:: 2.00000
|
||||
sub_part: ANA-000002-001 | L7805 - LDO
|
||||
sub_part.IPN: ANA-000002-001
|
||||
sub_part.name: L7805
|
||||
sub_part.build_order_allocations: <QuerySet [<BuildItem: BuildItem object (5)>]>
|
||||
........
|
||||
```
|
||||
{% 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 %}
|
||||
|
||||
|
@ -22,39 +22,6 @@ Each report has access to a number of context variables by default. The followin
|
||||
| request | Django request object |
|
||||
| user | User who made the request to render the template |
|
||||
|
||||
#### Build Order
|
||||
|
||||
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](./context_variables.md#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
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| part | The [Part](./context_variables.md#part) to be built (from component BOM items) |
|
||||
| reference | Build order reference (required, must be unique) |
|
||||
| title | Brief title describing the build (required) |
|
||||
| quantity | Number of units to be built |
|
||||
| parent | Reference to a [Build](./context_variables.md#build) object for which this Build is required |
|
||||
| sales_order | References to a [Sales Order](./context_variables.md#salesorder) object for which this [Build](./context_variables.md#build) is required (e.g. the output of this build will be used to fulfil a sales order) |
|
||||
| take_from | [StockLocation](./context_variables.md#stocklocation) to take stock from to make this build (if blank, can take from anywhere) |
|
||||
| status | Build status code |
|
||||
| batch | Batch code transferred to build parts (optional) |
|
||||
| creation_date | Date the build was created (auto) |
|
||||
| target_date | Date the build will be overdue |
|
||||
| completion_date | Date the build was completed (or, if incomplete, the expected date of completion) |
|
||||
| link | External URL for extra information |
|
||||
| notes | Text notes |
|
||||
| completed_by | User that completed the build |
|
||||
| issued_by | User that issued the build |
|
||||
| responsible | User (or group) responsible for completing the build |
|
||||
|
||||
#### Label
|
||||
|
||||
Certain types of labels have different context variables then other labels.
|
||||
@ -128,6 +95,7 @@ Each part object has access to a lot of context variables about the part. The fo
|
||||
| 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 |
|
||||
|
Loading…
x
Reference in New Issue
Block a user