mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-12 10:05:39 +00:00
Add database model for defining custom units (#5268)
* Add database model for defining custom units - Database model - DRF serializer - API endpoints * Add validation hook * Custom check for the 'definition' field * Add settings page for custom units - Table of units - Create / edit / delete buttons * Allow "unit" field to be empty - Not actually required for custom unit definition * Load custom unit definitions into global registry * Docs: add core concepts page(s) * Add some back links * Update docs * Add unit test for custom unit conversion * More unit testing * remove print statements * Add missing table rule
This commit is contained in:
41
docs/docs/concepts/units.md
Normal file
41
docs/docs/concepts/units.md
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
title: Physical Units
|
||||
---
|
||||
|
||||
## Physical Units
|
||||
|
||||
Support for real-world "physical" units of measure is implemented using the [pint](https://pint.readthedocs.io/en/stable/) Python library. This library provides the following core functions:
|
||||
|
||||
- Ensures consistent use of real units for your inventory management
|
||||
- Convert between compatible units of measure from suppliers
|
||||
- Enforce use of compatible units when creating part parameters
|
||||
- Enable custom units as required
|
||||
|
||||
## Unit Support
|
||||
|
||||
Physical units are supported by the following InvenTree subsystems:
|
||||
|
||||
### Part
|
||||
|
||||
The [unit of measure](../part/part.md#units-of-measure) field for the [Part](../part/part.md) model uses real-world units.
|
||||
|
||||
### Supplier Part
|
||||
|
||||
The [supplier part](../part/part/#supplier-parts) model uses real-world units to convert between supplier part quantities and internal stock quantities. Unit conversion rules ensure that only compatible unit types can be supplied
|
||||
|
||||
### Part Parameter
|
||||
|
||||
The [part parameter template](../part/parameter.md#parameter-templates) model can specify units of measure, and part parameters can be specified against these templates with compatible units
|
||||
|
||||
## Custom Units
|
||||
|
||||
Out of the box, the Pint library provides a wide range of units for use. However, it may not be sufficient for a given application. In such cases, custom units can be easily defined to meet custom requirements.
|
||||
|
||||
Custom units can be defined to provide a new physical quantity, link existing units together, or simply provide an alias for an existing unit.
|
||||
|
||||
!!! tip "More Info"
|
||||
For further information, refer to the [pint documentation](https://pint.readthedocs.io/en/stable/advanced/defining.html) regarding custom unit definition
|
||||
|
||||
### Create Custom Units
|
||||
|
||||
To view, edit and create custom units, locate the *Physical Units* tab in the [settings panel](../settings/global.md).
|
@ -77,13 +77,13 @@ The parametric parts table allows the returned parts to be sorted by particular
|
||||
|
||||
## Parameter Units
|
||||
|
||||
The *units* field (which is defined against a [parameter template](#parameter-templates)) defines the base unit of that template. Any parameters which are created against that unit *must* be specified in compatible units. Unit conversion is implemented using the [pint](https://pint.readthedocs.io/en/stable/) Python library. This conversion library is used to perform two main functions:
|
||||
|
||||
- Enforce use of compatible units when creating part parameters
|
||||
- Perform conversion to the base template unit
|
||||
The *units* field (which is defined against a [parameter template](#parameter-templates)) defines the base unit of that template. Any parameters which are created against that unit *must* be specified in compatible units.
|
||||
|
||||
The in-built conversion functionality means that parameter values can be input in different dimensions - *as long as the dimension is compatible with the base template units*.
|
||||
|
||||
!!! info "Read Mode"
|
||||
Read more about how InvenTree supports [physical units of measure](../concepts/units.md)
|
||||
|
||||
### Incompatible Units
|
||||
|
||||
If a part parameter is created with a value which is incompatible with the units specified for the template, it will be rejected:
|
||||
|
@ -81,6 +81,9 @@ By default, all parts are *Active*. Marking a part as inactive means it is not a
|
||||
|
||||
Each type of part can define a custom "unit of measure" which is a standardized unit which is used to track quantities for a particular part. By default, the "unit of measure" for each part is blank, which means that each part is tracked in dimensionless quantities of "pieces".
|
||||
|
||||
!!! info "Read More"
|
||||
Read more on how InvenTree supports [physical units of measure](../concepts/units.md)
|
||||
|
||||
### Physical Units
|
||||
|
||||
It is possible to track parts using physical quantity values, such as *metres* or *litres*. For example, it would make sense to track a "wire" in units of "metres":
|
||||
|
@ -70,15 +70,17 @@ nav:
|
||||
- InvenTree:
|
||||
- InvenTree: index.md
|
||||
- Features: features.md
|
||||
- Release Notes: releases/release_notes.md
|
||||
- FAQ: faq.md
|
||||
- Credits: credits.md
|
||||
- Privacy: privacy.md
|
||||
- Terminology: terminology.md
|
||||
- Core Concepts:
|
||||
- Terminology: concepts/terminology.md
|
||||
- Physical Units: concepts/units.md
|
||||
- Development:
|
||||
- Getting started: develop/starting.md
|
||||
- Contributing: develop/contributing.md
|
||||
- Devcontainer: develop/devcontainer.md
|
||||
- Credits: credits.md
|
||||
- Privacy: privacy.md
|
||||
- Release Notes: releases/release_notes.md
|
||||
- Install:
|
||||
- Introduction: start/intro.md
|
||||
- Configuration: start/config.md
|
||||
|
Reference in New Issue
Block a user