mirror of
https://github.com/grocy/grocy.git
synced 2025-10-14 09:11:11 +00:00
Grocycode, label printing (#1500)
* Grocycode: Productpicker, StockService * Grocycode: Datamatrix generation * Grocycode: Display in UI, make Images downloadable * Grocycode: Do not show on product card * Grocycode: Stockentry Label view * Grocycode: Webhooks & Labelprinter Feature * Grocycode: Manual Label printing * Grocycode: Print Label from product form * Quagga2: use zxing for DataMatrix recognition * Grocycode: Default settings for label printing * Prepare merge of master * Grocycode: docs * Docs: label printing webhook * Review - "grocy" is currently written lower-case everywhere, so let's do this also for "grocycode" - Unified phrases / capitalization - Minor UI adjustments (mainly context menu item ordering / ordering/spacing on product edit page) - Documented API changes for Swagger UI (grocy.openapi.json) - Reverted German localizations (those are managed via Transifex; would cause conflicts when manually edited - will import them later there) - Reverted a somehow messed up localization string (productform/help text for `cumulate_min_stock_amount_of_sub_products`) - Suppress deprecation warnings when generating Datamatrix PNG (otherwise the PNG is invalid, https://github.com/jucksearm/php-barcode/issues/3) - Default `FEATURE_FLAG_LABELPRINTER` to disabled Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
66
docs/grocycode.md
Normal file
66
docs/grocycode.md
Normal file
@@ -0,0 +1,66 @@
|
||||
grocycode
|
||||
==========
|
||||
|
||||
grocycode is, in essence, a simple way to reference to arbitrary grocy entities.
|
||||
Each grocycode includes a magic, an entitiy identifier, an id and an ordered set of extra data.
|
||||
It is supported to be entered anywhere grocy expects one to read a barcode, but can also reference
|
||||
grocy-internal properties like specific stock entries, or specific batteries.
|
||||
|
||||
Serialization
|
||||
----
|
||||
|
||||
There are three mandatory parts in a grocycode:
|
||||
|
||||
1. The magic `grcy`
|
||||
2. An entity identifer matching the regular expression `[a-z]+` (that is, lowercase english alphabet without any fancy accents, minimum length 1 character).
|
||||
3. An object identifer matching the regular expression `[0-9]+`
|
||||
|
||||
Optionally, any number of further data without format restrictions besides not containing any double colons [0] may be appended.
|
||||
|
||||
These parts are then linearly appended, seperated by a double colon `:`.
|
||||
|
||||
Entity Identifers
|
||||
----
|
||||
|
||||
Currently, there are three different entity types defined:
|
||||
|
||||
- `p` for Products
|
||||
- `b` for Batteries
|
||||
- `c` for Chores
|
||||
|
||||
Example
|
||||
----
|
||||
|
||||
In this example, we encode a *Product* with ID *13*, which results in `grcy:p:13` when serialized.
|
||||
|
||||
Product grocycodes
|
||||
----
|
||||
|
||||
Product grocycodes extend the data format to include an optional stock id, thus may reference a specific stock entry directly.
|
||||
|
||||
Example: `grcy:p:13:60bf8b5244b04`
|
||||
|
||||
Battery grocycodes
|
||||
----
|
||||
|
||||
Currently, Battery grocycodes do not define any extra fields.
|
||||
|
||||
Chore grocycodes
|
||||
----
|
||||
|
||||
Currently, Chore grocycodes do not define any extra fields.
|
||||
|
||||
Visual Encoding
|
||||
----
|
||||
|
||||
Grocy uses DataMatrix 2D Barcodes to encode grocycodes into a visual representation. In principle, there is no problem with using
|
||||
other encoding formats like QR codes; however DataMatrix uses less space for the same information and redundancy and is a bit
|
||||
easier read by 2D barcode scanners, especially on non-flat surfaces.
|
||||
|
||||
You can pick up cheap-ish used scanners from ebay (about 45€ in germany). Make sure to set them to the correct keyboard emulation,
|
||||
so that the double colons get entered correctly.
|
||||
|
||||
|
||||
Notes
|
||||
---
|
||||
[0]: Obviously, it needs to be encoded into some usable visual representation and then read. So probably you only want to encode stuff that can be typed on a keyboard.
|
40
docs/label-printing.md
Normal file
40
docs/label-printing.md
Normal file
@@ -0,0 +1,40 @@
|
||||
Label printing
|
||||
====
|
||||
|
||||
To enable label printing, set `FEATURE_FLAG_LABELPRINTER` to `true`in your `config.php`. You also need to provide a webhook target that is responsible for printing.
|
||||
|
||||
Why webhook?
|
||||
---
|
||||
|
||||
Label printers come in all shapes and forms, and your particular one is probably not the one used by the author of this feature. Also, grocy may does not have a
|
||||
direct connection to a local label printer (e.g. grocy is hosted in a cloud vps). Thus, a lightweight implementation is provided by grocy: whenever something
|
||||
should print, a POST request to a configured URL is made. The target then is responsible for label printing.
|
||||
|
||||
Reference implementation
|
||||
---
|
||||
|
||||
The webhook was developed and tested against a Brother QL-600 label printer, using endless 62mm label paper. The webhook provider implementation was
|
||||
implemented into [a fork of brother_ql_web](https://github.com/mistressofjellyfish/brother_ql_web).
|
||||
|
||||
Webhook request
|
||||
---
|
||||
|
||||
Requests can be configured to be sent server-side (that is, from the machine hosting grocy through GuzzleHttp) or by an AJAX request directly from the browser.
|
||||
The latter is neccesary for situations where the grocy hosting machine cannot reach your label printer, however server-side requests are a bit faster and
|
||||
tend to be more stable.
|
||||
|
||||
Both methods fire this request upon printing:
|
||||
|
||||
```
|
||||
POST /your/printing/api/endpoint HTTP/1.1
|
||||
|
||||
product=<productname>&grocycode=grocy:x:xxx&duedate=DD:%2021-06-09&...
|
||||
|
||||
```
|
||||
|
||||
If specified, the request body may also be JSON encoded, however the fields stay the same.
|
||||
|
||||
Additional POST parameters (like the font to use) may be supplied in `config.php`. Keep in mind that these config values will be distributed to all clients on all requests
|
||||
if the webhook is configured to run client-side.
|
||||
|
||||
The webhook receiver is required to layout and print the resulting label.
|
Reference in New Issue
Block a user