mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-06-12 18:25:27 +00:00
Initial commit
- Copied from inventree.github.io
This commit is contained in:
34
docs/extend/api.md
Normal file
34
docs/extend/api.md
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
title: InvenTree API
|
||||
layout: page
|
||||
---
|
||||
|
||||
## InvenTree API
|
||||
|
||||
InvenTree provides a powerful REST API for interacting with inventory data on the server. Low-level data access and manipulation is available, with integrated user authentication and data validation
|
||||
|
||||
### Documentation
|
||||
|
||||
The API is self-documenting, and the documentation is provided alongside any InvenTree installation instance. If (for example) you have an InvenTree instance running at `http://127.0.0.1:8000` then the API documentation is available at `http://127.0.0.1:8000/api-doc/`
|
||||
|
||||
{% with id="api_doc", url="api/api_doc.png", description="API documentation" %}
|
||||
{% include 'img.html' %}
|
||||
{% endwith %}
|
||||
|
||||
### Authentication
|
||||
|
||||
The API uses token-based authentication for fast data access. To obtain a valid token, perform a GET request to `/api/user/token/` (no data are required).
|
||||
|
||||
!!! info "Credentials"
|
||||
Ensure that a valid username:password combination are supplied as basic authorization headers.
|
||||
|
||||
If the supplied user credentials are validated, the server will respond with:
|
||||
|
||||
```
|
||||
HTTP_200_OK
|
||||
{
|
||||
token: "usertokendatastring",
|
||||
}
|
||||
```
|
||||
|
||||
After reception of a valid authentication token, it can be subsequently used to perform token-based authentication.
|
16
docs/extend/integrate.md
Normal file
16
docs/extend/integrate.md
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
title: Third Party Integrations
|
||||
layout: page
|
||||
---
|
||||
|
||||
## Third Party Integrations
|
||||
|
||||
A list of known third-party InvenTree extensions is provided below. If you have an extension that should be listed here, contact the InvenTree team on [GitHub](https://github.com/inventree/).
|
||||
|
||||
### Ki-nTree
|
||||
|
||||
[Ki-nTree](https://github.com/sparkmicro/Ki-nTree/) is a fantastic tool for automated creation of [KiCad](https://kicad-pcb.org/) library parts, with direct integration with InvenTree.
|
||||
|
||||
### inventree-docker
|
||||
|
||||
[inventree-docker](https://github.com/Zeigren/inventree-docker) provides Docker support for InvenTree
|
58
docs/extend/plugins.md
Normal file
58
docs/extend/plugins.md
Normal file
@ -0,0 +1,58 @@
|
||||
---
|
||||
title: Plugins
|
||||
layout: page
|
||||
---
|
||||
|
||||
## InvenTree Plugin Architecture
|
||||
|
||||
The InvenTree server code supports an extensible plugin architecture, allowing custom plugins to be integrated directly into the database server. This allows development of complex behaviours which are decoupled from core InvenTree code.
|
||||
|
||||
InvenTree plugins are located in the directory `./InvenTree/plugins/`.
|
||||
|
||||
Plugins are discovered and loaded when the server is started.
|
||||
|
||||
Multiple plugins are supported:
|
||||
|
||||
### Reporting Plugins
|
||||
|
||||
InvenTree can generate customized reports (for example stocktake information, packing lists, acceptance test reports, etc). The reporting interface is extremely versatile, allowing the generation of reports in multiple formats (PDF / LaTeX / etc).
|
||||
|
||||
!!! missing "TODO"
|
||||
Include more information here on reporting plugins
|
||||
|
||||
### Barcode Plugins
|
||||
|
||||
InvenTree supports decoding of arbitrary barcode data via a **Barcode Plugin** interface. Barcode data POSTed to the `/api/barcode/` endpoint will be supplied to all loaded barcode plugins, and the first plugin to successfully interpret the barcode data will return a response to the client.
|
||||
|
||||
InvenTree can generate native QR codes to represent database objects (e.g. a single StockItem). This barcode can then be used to perform quick lookup of a stock item or location in the database. A client application (for example the InvenTree mobile app) scans a barcode, and sends the barcode data to the InvenTree server. The server then uses the **InvenTreeBarcodePlugin** (found at `/InvenTree/plugins/barcode/inventree.py`) to decode the supplied barcode data.
|
||||
|
||||
Any third-party barcodes can be decoded by writing a matching plugin to decode the barcode data. These plugins could then perform a server-side action, or render a JSON response back to the client for further action.
|
||||
|
||||
Some examples of possible uses for barcode integration:
|
||||
|
||||
- Stock lookup by scanning a barcode on a box of items
|
||||
- Receiving goods against a PurchaseOrder by scanning a supplier barcode
|
||||
- Perform a stock adjustment action (e.g. take 10 parts from stock whenever a barcode is scanned)
|
||||
|
||||
Barcode data are POSTed to the server as follows:
|
||||
|
||||
```
|
||||
POST {
|
||||
barcode_data: "[(>someBarcodeDataWhichThePluginKnowsHowToDealWith"
|
||||
}
|
||||
```
|
||||
|
||||
### Action Plugins
|
||||
|
||||
Arbitrary "actions" can be called by POSTing data to the `/api/action/` endpoint. The POST request must include the name of the action to be performed, and a matching ActionPlugin plugin must be loaded by the server. Arbitrary data can also be provided to the action plugin via the POST data:
|
||||
|
||||
```
|
||||
POST {
|
||||
action: "MyCustomAction",
|
||||
data: {
|
||||
foo: "bar",
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For an example of a very simple action plugin, refer to `/InvenTree/plugins/action/action.py`
|
120
docs/extend/python.md
Normal file
120
docs/extend/python.md
Normal file
@ -0,0 +1,120 @@
|
||||
---
|
||||
title: Python Interface
|
||||
layout: page
|
||||
---
|
||||
|
||||
## Python Module
|
||||
|
||||
A [Python module](https://github.com/inventree/inventree-python) is provided for rapid development of third party scripts or applications using the REST API. The python module handles authentication and API transactions, providing an extremely clean interface for interacting with and manipulating database data.
|
||||
|
||||
### Features
|
||||
|
||||
- Automatic authentication management using token-based authentication
|
||||
- Pythonic data access
|
||||
- Native file uploads
|
||||
- Powerful functions for accessing related model data
|
||||
|
||||
### Installation
|
||||
|
||||
The inventree python interface can be easily installed via the [PIP package manager](https://pypi.org/project/inventree/):
|
||||
|
||||
```
|
||||
pip3 install inventree
|
||||
```
|
||||
|
||||
Alternatively, it can downloaded and installed from source, from [GitHub](https://github.com/inventree/inventree-python).
|
||||
|
||||
### Examples
|
||||
|
||||
The inventree Python module is designed to be very lightweight and simple to use. Some simple examples are provided below:
|
||||
|
||||
#### Authentication
|
||||
|
||||
Authentication against an InvenTree server is simple:
|
||||
|
||||
```python
|
||||
from inventree.api import InvenTreeAPI
|
||||
|
||||
SERVER_ADDRESS = 'http://127.0.0.1:8000'
|
||||
MY_USERNAME = 'not_my_real_username'
|
||||
MY_PASSWORD = 'not_my_real_password'
|
||||
|
||||
api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD)
|
||||
```
|
||||
|
||||
Alternatively, if you already have an access token:
|
||||
|
||||
```python
|
||||
api = InvenTreeAPI(SERVER_ADDRESS, token=MY_TOKEN)
|
||||
```
|
||||
|
||||
#### Retrieving Individual Items
|
||||
|
||||
If the primary-key of an object is already known, retrieving it from the database is performed as follows:
|
||||
|
||||
```python
|
||||
from inventree.part import PartCategory
|
||||
|
||||
category = PartCatgory(api, 10)
|
||||
```
|
||||
|
||||
#### Querying / Listing Items
|
||||
|
||||
Database items can be queried by using the `list` method for the given class:
|
||||
|
||||
```python
|
||||
from inventree.part import Part
|
||||
from inventree.stock import StockItem
|
||||
|
||||
parts = Part.list(api, category=10, assembly=True)
|
||||
items = StockItem.list(api, location=4, part=24)
|
||||
```
|
||||
|
||||
Once an object has been retrieved from the database, its related objects can be returned with helper functions:
|
||||
|
||||
```python
|
||||
part = Part(api, 25)
|
||||
stock_items = part.getStockItems()
|
||||
```
|
||||
|
||||
Some classes also have helper functions for performing certain actions, such as uploading file attachments or test results:
|
||||
|
||||
```python
|
||||
stock_item = StockItem(api, 1001)
|
||||
stock_item.uploadTestResult("Firmware", True, value="0x12345678", attachment="device_firmware.bin")
|
||||
```
|
||||
|
||||
#### Creating New Items
|
||||
|
||||
```python
|
||||
from inventree.part import Part, PartCategory
|
||||
from inventree.stock import StockItem
|
||||
|
||||
## Create a new PartCategory object,
|
||||
## underneath the existing category with pk 7
|
||||
furniture = PartCategory.create(api, {
|
||||
'name': 'Furniture',
|
||||
'description': 'Chairs, tables, etc',
|
||||
parent, 7
|
||||
})
|
||||
|
||||
## Create a new Part
|
||||
## Use the pk (primary-key) of the newly created category
|
||||
couch = Part.create(api, {
|
||||
'name': 'Couch',
|
||||
'description': 'Long thing for sitting on',
|
||||
'category': furniture.pk,
|
||||
'active': True,
|
||||
'virtual': False,
|
||||
## Note - You do not have to fill out *all* fields
|
||||
})
|
||||
|
||||
## Create a new StockItem
|
||||
item = StockItem.create(api, {
|
||||
'part': couch.pk,
|
||||
'quantity': 5,
|
||||
'notes': 'A stack of couches',
|
||||
location: 10, ## PK of a StockLocation already in the database...
|
||||
})
|
||||
|
||||
```
|
Reference in New Issue
Block a user