2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-12 10:05:39 +00:00

Build line labels (#5034)

* Adds BuildLineLabel model

- New type of label for printing against BuildLine objects

* Add serializer for new model

* Add API endpoints for new label type

* Add hooks to BuildLine table

* Create default label

- Create an example BuildLineLabel object

* Add admin integration

* Fix js code

* Use two-tiered template

- Allows base template to be updated

* Improve default label

* Add docs pages for labels

* Update nav

* Documentation for new label

* Add permission role

* Bump API version
This commit is contained in:
Oliver
2023-06-14 13:07:18 +10:00
committed by GitHub
parent a3940cfc41
commit 8d16abcefb
19 changed files with 515 additions and 142 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 KiB

View File

@ -11,6 +11,17 @@ Custom labels can be generated using simple HTML templates, with support for QR-
Simple (generic) label templates are supplied 'out of the box' with InvenTree - however support is provided for generation of extremely specific custom labels, to meet any particular requirement.
## Label Types
The following types of labels are available
| Label Type | Description |
| --- | --- |
| [Part Labels](./labels/part_labels.md) | Print labels for individual parts |
| [Stock Labels](./labels/stock_labels.md) | Print labels for individual stock items |
| [Location Labels](./labels/location_labels.md) | Print labels for individual stock locations
| [Build Labels](./labels/build_labels.md) | Print labels for individual build order line items |
## Label Templates
Label templates are written using a mixture of [HTML](https://www.w3schools.com/html/) and [CSS](https://www.w3schools.com/css). [Weasyprint](https://weasyprint.org/) templates support a *subset* of HTML and CSS features. In addition to supporting HTML and CSS formatting, the label templates support the Django templating engine, allowing conditional formatting of the label data.
@ -189,133 +200,3 @@ To extend this template in a custom uploaded label, simply extend as follows:
{% 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 %}
```
Note that for parameters which include a `space` character in their name, lookup using the "dot" notation won't work! In this case, try using the [key lookup](./helpers.md#key-access) method:
```html
{% raw %}
Voltage Rating: {% getkey parameters "Voltage Rating" %}
{% endraw %}
```

View File

@ -0,0 +1,118 @@
---
title: Build Labels
---
## Build Line Labels
Build label templates are used to generate labels for individual build order line items.
### Creating Build Line Label Templates
Build label templates are added (and edited) via the [admin interface](../../settings/admin.md).
### Printing Build Line Labels
Build line labels are printed from the Build Order page, under the *Allocate Stock* tab. Multiple line items can be selected for printing:
{% with id='print_build_labels', url='report/label_build_print.png', description='Print build line labels' %}
{% include 'img.html' %}
{% endwith %}
### Context Data
The following context variables are made available to the Build Line label template:
| Variable | Description |
| --- | --- |
| build_line | The build_line instance |
| build | The build order to which the build_line is linked |
| bom_item | The bom_item to which the build_line is linked |
| part | The required part for this build_line instance. References bom_item.sub_part |
| quantity | The total quantity required for the build line |
| allocated_quantity | The total quantity which has been allocated against the build line |
| allocations | A queryset containing the allocations made against the build_line |
## Example
A simple example template is shown below:
```html
{% raw %}
{% extends "label/label_base.html" %}
{% load barcode report %}
{% load inventree_extras %}
{% block style %}
{{ block.super }}
.label {
margin: 1mm;
}
.qr {
height: 28mm;
width: 28mm;
position: relative;
top: 0mm;
right: 0mm;
float: right;
}
.label-table {
width: 100%;
border-collapse: collapse;
border: 1pt solid black;
}
.label-table tr {
width: 100%;
border-bottom: 1pt solid black;
padding: 2.5mm;
}
.label-table td {
padding: 3mm;
}
{% endblock style %}
{% block content %}
<div class='label'>
<table class='label-table'>
<tr>
<td>
<b>Build Order:</b> {{ build.reference }}<br>
<b>Build Qty:</b> {% decimal build.quantity %}<br>
</td>
<td>
<img class='qr' alt='build qr' src='{% qrcode build.barcode %}'>
</td>
</tr>
<tr>
<td>
<b>Part:</b> {{ part.name }}<br>
{% if part.IPN %}
<b>IPN:</b> {{ part.IPN }}<br>
{% endif %}
<b>Qty / Unit:</b> {% decimal bom_item.quantity %} {% if part.units %}[{{ part.units }}]{% endif %}<br>
<b>Qty Total:</b> {% decimal quantity %} {% if part.units %}[{{ part.units }}]{% endif %}
</td>
<td>
<img class='qr' alt='part qr' src='{% qrcode part.barcode %}'>
</td>
</tr>
</table>
</div>
{% endblock content %}
{% endraw %}
```
Which results in a label like:
{% with id='build_label_example', url='report/label_build_example.png', description='Example build line labels' %}
{% include 'img.html' %}
{% endwith %}

View File

@ -0,0 +1,24 @@
---
title: Location Labels
---
## Stock Location Labels
Stock Location label templates are used to generate labels for individual Stock Locations.
### Creating Stock Location Label Templates
Stock Location label templates are added (and edited) via the admin interface.
### Printing Stock Location Labels
To print a single label from the Stock Location detail view, select the *Print Label* option.
### Context Data
The following variables are made available to the StockLocation label template:
| Variable | Description |
| -------- | ----------- |
| location | The [StockLocation](../context_variables.md#stocklocation) object itself |

View File

@ -0,0 +1,57 @@
---
title: Part Labels
---
## Part Labels
Part label templates are used to generate labels for individual Part instances.
### Creating Part Label Templates
Part label templates are added (and edited) via the admin interface.
### Printing Part Labels
Part label can be printed using the following approaches:
To print a single part label from the Part detail view, select the *Print Label* option.
To print multiple part labels, select multiple parts in the part table and select the *Print Labels* option.
### Context Data
The following context variables are made available to the Part label template:
| Variable | Description |
| -------- | ----------- |
| part | The [Part](../context_variables.md#part) object |
| category | The [Part Category](../context_variables.md#part-category) which contains the Part |
| name | The name of the part |
| description | The description text for the part |
| IPN | Internal part number (IPN) for the part |
| revision | Part revision code |
| qr_data | String data which can be rendered to a QR code |
| parameters | Map (Python dictionary) object containing the parameters associated with the part instance |
#### 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 %}
```
Note that for parameters which include a `space` character in their name, lookup using the "dot" notation won't work! In this case, try using the [key lookup](../helpers.md#key-access) method:
```html
{% raw %}
Voltage Rating: {% getkey parameters "Voltage Rating" %}
{% endraw %}
```

View File

@ -0,0 +1,61 @@
---
title: Stock Labels
---
## Stock Item Labels
Stock Item label templates are used to generate labels for individual Stock Items.
### Creating Stock Item Label Templates
Stock Item label templates are added (and edited) via the admin interface.
### Printing Stock Item Labels
Stock Item labels can be printed using the following approaches:
To print a single stock item from the Stock Item detail view, select the *Print Label* option as shown below:
{% with id='item_label_single', url='report/label_stock_print_single.png', description='Print single stock item label' %}
{% include 'img.html' %}
{% endwith %}
To print multiple stock items from the Stock table view, select the *Print Labels* option as shown below:
{% with id='item_label_multiple', url='report/label_stock_print_multiple.png', description='Print multiple stock item labels' %}
{% include 'img.html' %}
{% endwith %}
### Context Data
The following variables are made available to the StockItem label template:
| Variable | Description |
| -------- | ----------- |
| item | The [StockItem](../context_variables.md#stockitem) object itself |
| part | The [Part](../context_variables.md#part) object which is referenced by the [StockItem](../context_variables.md#stockitem) object |
| name | The `name` field of the associated Part object |
| ipn | The `IPN` field of the associated Part object |
| revision | The `revision` field of the associated Part object |
| quantity | The `quantity` field of the StockItem object |
| serial | The `serial` field of the StockItem object |
| uid | The `uid` field of the StockItem object |
| tests | Dict object of TestResult data associated with the StockItem |
| parameters | Dict object containing the parameters associated with the base Part |
### URL-style QR code
Stock Item labels support [QR code](../barcodes.md#qr-code) containing the stock item URL, which can be
scanned and opened directly
on a portable device using the camera or a QR code scanner. To generate a URL-style QR code for stock item in the [label HTML template](../labels.md#label-templates), add the
following HTML tag:
``` html
{% raw %}
<img class='custom_qr_class' src='{% qrcode qr_url %}'>
{% endraw %}
```
Make sure to customize the `custom_qr_class` CSS class to define the position of the QR code
on the label.

View File

@ -138,7 +138,12 @@ nav:
- Sales Order: report/sales_order.md
- Return Order: report/return_order.md
- BOM: report/bom.md
- Labels: report/labels.md
- Labels:
- Custom Labels: report/labels.md
- Part Labels: report/labels/part_labels.md
- Stock Labels: report/labels/stock_labels.md
- Location Labels: report/labels/location_labels.md
- Build Labels: report/labels/build_labels.md
- Helper Functions: report/helpers.md
- Barcodes: report/barcodes.md
- Context Variables: report/context_variables.md