Metadata-Version: 2.4
Name: inventree-wurth-barcode
Version: 0.1.2
Summary: InvenTree plugin: scan the barcodes of the Würth Elektronik labels (part lookup and purchase order receiving)
Author-email: Simone Amadori <simone@amadori.bs.it>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Kamaar/inventree-wurth-barcode
Project-URL: Repository, https://github.com/Kamaar/inventree-wurth-barcode
Project-URL: Issues, https://github.com/Kamaar/inventree-wurth-barcode/issues
Keywords: inventree,plugin,barcode,wurth,wurth-elektronik,datamatrix
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Framework :: InvenTree
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Würth Elektronik Barcode

[InvenTree](https://inventree.org) plugin (>= 1.0) that reads the barcodes of the **Würth Elektronik** labels, from the
web interface and from the **InvenTree app**: scanning a label opens the part, and inside a purchase order it receives
the line item with the quantity of the label.

## The labels

The Würth Elektronik labels (reels, bags, samples) carry the ANSI MH10.8.2 data identifiers:

| Identifier | Field | Example |
|---|---|---|
| `1P` | Part number (Würth order code = manufacturer part number) | `609 002 134 21` |
| `Q` | Quantity | `10` |
| `1T` | Lot number | `298010012537000` |
| `16D` | Production date | `20250908` |

The **DataMatrix** holds all of them (ISO/IEC 15434 format 06:
`[)>␞06␝1P60900213421␝Q10␝1T298010012537000␝16D20250908␞␄`); each **Code 128** barcode holds one field. The plugin
reads the DataMatrix and the part number barcode (`1P…`).

The label names no supplier: it is recognised by its content, a numeric `1P` and none of the fields that distributors
add to their own labels (DigiKey `P` / `30P`, Mouser and DigiKey `11K`), so it is not confused with them.

## What a scan does

- **Part lookup** (scan from the home page, web or app):
  - the **supplier part** of the Würth supplier, with the order code as SKU;
  - the **manufacturer part** of Würth Elektronik with the order code as MPN, also when the part is bought from a
    distributor (e.g. Mouser).

  Spaces are ignored: `609 002 134 21` and `60900213421` are the same code.
- **Purchase order receiving** (*Purchase order → Scan to receive*, web or app): in a placed order of the Würth supplier
  the line item of the part is received with the quantity of the label, into the destination of the line or of the
  order.

## Installation

The plugin is on [PyPI](https://pypi.org/project/inventree-wurth-barcode/):

- **from the InvenTree UI** (*Settings → Plugins → Install plugin*): *Package Name* `inventree-wurth-barcode`;
- **or with `plugins.txt`** (next to `config.yaml`, or the file set by `INVENTREE_PLUGIN_FILE`): a line
  `inventree-wurth-barcode`.

Then activate **Würth Elektronik Barcode** in *Settings → Plugins* and restart server and worker. The plugin has no
database tables: no migrations are needed. With Docker, install it in **both** the server and the worker container
(different versions cause the *Plugin Registry Mismatch* error, INVE-E20):

```bash
docker compose exec inventree-server invoke plugins
docker compose exec inventree-worker invoke plugins
docker compose restart inventree-server inventree-worker
```

With the package installer (`.deb`): `sudo inventree run invoke plugins`, then `sudo inventree restart`.

The **InvenTree app** needs no change: it sends the scanned barcodes to the server, which passes them to the active
barcode plugins.

## Settings

| Setting | Notes |
|---|---|
| `SUPPLIER_ID` | Supplier company of the parts bought from Würth Elektronik. If empty, the only active supplier whose name contains *Würth*, *Wurth* or *Wuerth* is used (and saved) |
| `MANUFACTURER_ID` | Manufacturer company of the Würth Elektronik parts. If empty, found by name as above |

Only active companies are listed and used: a selected company which is later deleted or deactivated is replaced by
the lookup by name.

## Development

```bash
python -m pytest            # parser tests, no InvenTree needed
ruff check wurth_barcode tests
```

`tests/integration` runs on a real InvenTree (`INVENTREE_SRC` set): the GitLab CI uses the
`inventree/inventree:stable` image with a SQLite database. Sample labels and their decoded barcodes are in
`docs/samples`.

## License

MIT
