mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-28 05:36:46 +00:00
Merge pull request #69 from SchrodingersGat/new-label
Update label printing docs
This commit is contained in:
commit
2b17ceae71
@ -8,6 +8,14 @@ title: Release 0.1.7
|
||||
|
||||
## New Features
|
||||
|
||||
### Label Printing
|
||||
|
||||
Label printing functionality has been simplified and brought into line with the PDF reporting functionality.
|
||||
|
||||
[#1342](https://github.com/inventree/InvenTree/pull/1342) represents a significant refactor of the label printing code.
|
||||
|
||||
!!! info "More Information"
|
||||
Refer to the [label printing documentation](../../report/labels) for further details.
|
||||
|
||||
## Major Bug Fixes
|
||||
| PR | Description |
|
||||
|
64
docs/report/barcodes.md
Normal file
64
docs/report/barcodes.md
Normal file
@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Barcode Generation
|
||||
---
|
||||
|
||||
## Barcode Generation
|
||||
|
||||
Both [report](../report) and [label](../labels) 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/codes.html) are also supported:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
|
||||
{% load barcode %}
|
||||
|
||||
<img class='custom_class' src='{% barcode "12345678" barcode_class="Code39" %}>
|
||||
{% 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 %}
|
||||
```
|
@ -4,18 +4,16 @@ title: Custom Labels
|
||||
|
||||
## Custom Labels
|
||||
|
||||
InvenTree supports printing of custom template-based labels, using the [blabel](https://github.com/Edinburgh-Genome-Foundry/blabel) Python library.
|
||||
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 Jinja template engine.
|
||||
|
||||
!!! info "Documentation"
|
||||
Refer to the [blabel documentation](https://edinburgh-genome-foundry.github.io/blabel/) for further information, and examples of the available features
|
||||
|
||||
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). The blabel library is based on [weasyprint](https://weasyprint.org/), which supports a *subset* of HTML and CSS features. In addition to supporting HTML and CSS formatting, the label templates support the Jinja templating engine, allowing conditional formatting of the label data.
|
||||
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 Jinja 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.
|
||||
|
||||
@ -29,8 +27,7 @@ Below is a reasonably simple example of a label template which demostrates much
|
||||
{% raw %}
|
||||
<style>
|
||||
@page {
|
||||
width: 75mm;
|
||||
height: 24mm;
|
||||
size: 75mm 24mm;
|
||||
padding: 1mm;
|
||||
}
|
||||
|
||||
@ -59,7 +56,7 @@ Below is a reasonably simple example of a label template which demostrates much
|
||||
|
||||
</style>
|
||||
|
||||
<img class='qr' src="{{ label_tools.qr_code(location.barcode) }}"/>
|
||||
<img class='qr' src="{% qrcode location.format_barcode %}"/>
|
||||
|
||||
<div class='location'>
|
||||
{{ location.name }}
|
||||
@ -99,11 +96,9 @@ Location Name: {{ location.name }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
### QR Codes
|
||||
### Barcodes
|
||||
|
||||
`blabel` supports barcodes and QR codes 'out of the box'. Passing data to render as a barcode or QR code is handled in the template file itself.
|
||||
|
||||
Refer to the [blabel docs](https://edinburgh-genome-foundry.github.io/blabel/) for further information.
|
||||
Refer to the [barcode documentation](../barcodes).
|
||||
|
||||
### Conditional Formatting
|
||||
|
||||
@ -127,10 +122,67 @@ As an example, consider a label template for a StockItem. A user may wish to def
|
||||
|
||||
To restrict the label accordingly, we could set the *filters* value to `part__IPN=IPN123`.
|
||||
|
||||
### Built-In Templates
|
||||
## 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.
|
||||
|
@ -71,12 +71,13 @@ nav:
|
||||
- Sales Orders: companies/so.md
|
||||
- Report:
|
||||
- Templates: report/report.md
|
||||
- Labels: report/labels.md
|
||||
- Reports:
|
||||
- Test Reports: report/test.md
|
||||
- Packing List: report/pack.md
|
||||
- Build Order: report/build.md
|
||||
- Order: report/order.md
|
||||
- Labels: report/labels.md
|
||||
- Barcodes: report/barcodes.md
|
||||
- Admin:
|
||||
- Admin Interface: admin/admin.md
|
||||
- User Permissions: admin/permissions.md
|
||||
|
Loading…
x
Reference in New Issue
Block a user