2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-10 13:51:01 +00:00

[refactor] Stocktake -> Stock History (#10124)

* Remove STOCKTAKE ruleset

* Adjust wording of settings

* Cleanup

* Improve text for global settings

* Add BulkDeleteMixin to "stocktake" endpoint

* Frontend updates

* Migrations

- Remove field 'last_stocktake' from Part model
- Remove fields 'user' and 'note' from PartStocktake model
- Remove model PartStocktakeReport

* Frontend cleanup

* Rename global setting

* Rewrite stocktake functionality

* Cleanup

* Adds custom exporter for part stocktake data

* Frontend cleanup

* Bump API version

* Tweaks

* Frontend updates

* Fix unit tests

* Fix helper func

* Add docs

* Fix broken link

* Docs updates

* Adjust playwright tests

* Add unit testing for plugin

* Add unit testing for stock history creation

* Fix unit test
This commit is contained in:
Oliver
2025-08-06 08:02:56 +10:00
committed by GitHub
parent b31e16eb98
commit 5574e7cf6b
46 changed files with 599 additions and 1123 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -1,8 +1,10 @@
---
title: Part Stocktake
title: Part Stock History
---
## Part Stocktake
## Part Stock History
InvenTree can track the historical stock levels of parts, allowing users to view past stocktake data and generate reports based on this information.
A *Stocktake* refers to a "snapshot" of stock levels for a particular part, at a specific point in time. Stocktake information is used for tracking a historical record of the quantity and value of part stock.
@@ -25,41 +27,33 @@ The total cost of stock on hand is calculated based on the provided pricing data
!!! info "Cost Range"
Cost data is provided as a *range* of values, accounting for any variability in available pricing data.
### Display Stocktake Data
### Display Historical Stock Data
Historical stocktake data for a particular part can be viewed in the *Stocktake* tab, available on the *Part* page.
Historical stock data for a particular part can be viewed in the *Stock History* tab, available on the *Part* page.
This tab displays a chart of historical stock quantity and cost data, and corresponding tabulated data:
{{ image("part/part_stocktake_tab.png", "Part stocktake tab") }}
If this tab is not visible, ensure that the *Part Stocktake* [user setting](../settings/user.md) is enabled in the *Display Settings* section.
If this tab is not visible, ensure that the *Enable Stock History* [user setting](../settings/user.md) is enabled in the *Display Settings* section.
{{ image("part/part_stocktake_enable_tab.png", "Enable stocktake tab") }}
{{ image("part/part_stocktake_enable_tab.png", "Enable stock history tab") }}
!!! info "Permission Required"
The stocktake tab will be unavailable if your user account does not have the [required permissions](#stocktake-permissions)
## Stocktake Reports
While a *Stocktake* entry records a historical snapshot of stock levels for a single *part*, a *Stocktake Report* is used to generate a report data file which contains stocktake entries for multiple parts. Stocktake reports can be generated for the entire range of parts available in the database, or a subset of parts as determined by user-configurable filters.
Stocktake reports can be [generated manually](#performing-a-stocktake) by the user, or (if enabled) [generated automatically](#automatic-stocktake) at a specified interval.
As there is a lot of data to crunch to build a report, stocktake reports are generated by the [background worker process](../settings/tasks.md). When the report is completed, it is saved to the database and made available for download.
!!! tip "Background Worker"
If the background worker process is not running, stocktake reports will be unavailable!
Stocktake reports are made available for download as a tabulated `.csv` file, which can be opened in many external applications for further analysis.
## Stocktake Settings
## Stock History Settings
There are a number of configuration options available in the [settings view](../settings/global.md):
{{ image("part/part_stocktake_settings.png", "Stocktake settings") }}
| Name | Description | Default | Units |
| ---- | ----------- | ------- | ----- |
{{ globalsetting("STOCKTAKE_ENABLE") }}
{{ globalsetting("STOCKTAKE_EXCLUDE_EXTERNAL") }}
{{ globalsetting("STOCKTAKE_AUTO_DAYS") }}
{{ globalsetting("STOCKTAKE_DELETE_OLD_ENTRIES")}}
{{ globalsetting("STOCKTAKE_DELETE_DAYS") }}
### Enable Stocktake
{{ image("part/part_stocktake_settings.png", "Stock history settings") }}
### Enable Stock History
Enable or disable stocktake functionality. Note that by default, stocktake functionality is disabled.
@@ -67,76 +61,10 @@ Enable or disable stocktake functionality. Note that by default, stocktake funct
Configure the number of days between generation of [automatic stocktake reports](#automatic-stocktake). If this value is set to zero, automatic stocktake reports will not be generated.
### Delete Old Reports
### Delete Old Stock History Entries
Configure how many days stocktake reports will be retained, before being deleted automatically.
If enabled, stock history entries older than the specified number of days will be automatically deleted from the database.
### Historical Stocktake Reports
### Stock History Deletion Interval
The *Stocktake Settings* display also provides a table of historical stocktake reports:
{{ image("part/part_stocktake_report_table.png", "Stocktake report table") }}
## Stocktake Permissions
Stocktake data and actions are protected by the [stocktake role](../settings/permissions.md#role):
| Permission | Actions Available |
| --- | --- |
| `stocktake.view` | View historical stocktake data for parts |
| `stocktake.add` | Perform stocktake and generate reports |
| `stocktake.delete` | Delete stocktake records and reports |
## Performing a Stocktake
Manual stocktake can be performed via the web interface in a number of locations. The user can filter the parts for which the stocktake will be performed. A new stocktake entry will be generated for each selected part, and optionally a report can be generated for download.
When performing a stocktake, various options are presented to the user:
{{ image("part/part_stocktake_generate.png", "Generate stocktake report") }}
| Option | Description |
| --- | --- |
| Part | Limit stocktake context to a part. If the selected part is a [template part](./index.md#template), any variant parts will also be included in the stocktake |
| Category | Limit stocktake context to a single [part category](./index.md#part-category). Parts which exist in child categories (under the selected parent category) will also be included. |
| Location | Limit stocktake context to a single [stock location](../stock/index.md#stock-location). Any parts which have stock items contained in this location (or any child locations) will be included in the stocktake |
| Generate Report | Select this option to generate a [stocktake report](#stocktake-reports) for the selected parts. |
| Update Parts | Select this option to save a new stocktake record for each selected part. |
### Part Stocktake
A stocktake report for a single part can be generated from the *Stocktake Tab* on the part page:
{{ image("part/part_stocktake_from_part.png", "Generate part stocktake report") }}
### Category Stocktake
A stocktake report for a part category can be generated from the *Part Category* page:
{{ image("part/part_stocktake_from_category.png", "Generate category stocktake report") }}
### Location Stocktake
A stocktake report for a stock location can be generated from the *Stock Location* page:
{{ image("part/part_stocktake_from_location.png", "Generate location stocktake report") }}
### Automatic Stocktake
If enabled, stocktake reports can be generated automatically at a configured interval, specified in number of days. Automatic stocktake reports are performed on the entire database of parts.
### API Functionality
Stocktake actions can also be performed via the [API](../api/index.md).
## Stocktake Settings
The following settings are available for stocktake:
| Name | Description | Default | Units |
| ---- | ----------- | ------- | ----- |
{{ globalsetting("STOCKTAKE_ENABLE") }}
{{ globalsetting("STOCKTAKE_EXCLUDE_EXTERNAL") }}
{{ globalsetting("STOCKTAKE_AUTO_DAYS") }}
{{ globalsetting("STOCKTAKE_DELETE_REPORT_DAYS") }}
{{ globalsetting("DISPLAY_PROFILE_INFO") }}
Configure how many days historical stock records are retained in the database.

View File

@@ -107,9 +107,9 @@ This tab is only displayed if the part is marked as *Purchaseable*.
The *Sales Orders* tab shows a list of the sales orders for this part. It provides a view for important sales order information like customer, status, creation and shipment dates.
### Stocktake
### Stock History
The *Stocktake* tab provide historical stock level information, based on user-provided stocktake data. Refer to the [stocktake documentation](./stocktake.md) for further information.
The *Stock History* tab provide historical stock level information. Refer to the [stock history documentation](./stocktake.md) for further information.
### Test Templates

View File

@@ -22,6 +22,7 @@ The following builtin plugins are available in InvenTree:
| Data Export | [BOM Exporter](./bom_exporter.md) | Custom [exporter](../mixins/export.md) for BOM data | Yes |
| Data Export | [InvenTree Exporter](./inventree_exporter.md) | Custom [exporter](../mixins/export.md) for InvenTree data | Yes |
| Data Export | [Parameter Exporter](./part_parameter_exporter.md) | Custom [exporter](../mixins/export.md) for part parameter data | Yes |
| Data Export | [Stocktake Exporter](./stocktake_exporter.md) | Custom [exporter](../mixins/export.md) for stocktake data | No |
| Events | [Auto Create Child Builds](./auto_create_builds.md) | Automatically create child build orders for sub-assemblies | No |
| Events | [Auto Issue Orders](./auto_issue.md) | Automatically issue pending orders when target date is reached | No |
| Label Printing | [Label Printer](./inventree_label.md) | Custom [label](../mixins/label.md) for InvenTree data | Yes |

View File

@@ -9,3 +9,7 @@ This plugin provides a mechanism to send notifications to a Slack channel when c
### API Key
To use this plugin, you need to provide a Slack API key. This key is used to authenticate the plugin with the Slack API and send messages to the specified channel.
### Activation
This plugin is an *optional* plugin, and must be enabled in the InvenTree settings.

View File

@@ -0,0 +1,35 @@
---
title: Stocktake Exporter
---
## Stocktake Exporter Plugin
The **Stocktake Exporter Plugin** provides custom "stocktake" export functionality for [Part](../../part/index.md) data.
It utilizes the [ExporterMixin](../mixins/export.md) mixin to provide a custom export format for stocktake data.
This exporter plugin can be used to export a comprehensive list of current stock levels for selected parts.
### Activation
This plugin is an *optional* plugin, and must be enabled in the InvenTree settings.
### Plugin Settings
There are no configurable settings for this plugin.
## Usage
This plugin is used in the same way as the [InvenTree Exporter Plugin](./inventree_exporter.md), but provides a custom export format for stocktake data.
### Export Options
When exporting part data, the *Stocktake Exporter* plugin is available for selection in the export dialog. When selected, the plugin provides some additional export options to control the data export process.
{{ image("stocktake_exporter_options.png", base="plugin/builtin", title="Stocktake Export Options") }}
| Option | Description |
|--------|-------------|
| `Pricing Data` | Include pricing data in the export. This will add columns for the cost of "stock on hand". |
| `Include External Stock` | Include stock from external warehouses in the export. This will add columns for the stock levels in external warehouses, and include the external quantities in the total stock count and valuation. |
| `Include Variant Items` | Include variant items in the export. This will add columns for the variant items associated with each part, and include the variant quantities in the total stock count and valuation. |

View File

@@ -184,7 +184,7 @@ Snippets are included in a template as follows:
{% raw %}{% include 'snippets/<snippet_name.html>' %}{% endraw %}
```
For example, consider a stocktake report for a particular stock location, where we wish to render a table with a row for each item in that location.
For example, consider a custom stocktake report for a particular stock location, where we wish to render a table with a row for each item in that location.
```html
{% raw %}

View File

@@ -257,6 +257,7 @@ nav:
- BOM Exporter: plugins/builtin/bom_exporter.md
- InvenTree Exporter: plugins/builtin/inventree_exporter.md
- Parameter Exporter: plugins/builtin/part_parameter_exporter.md
- Stocktake Exporter: plugins/builtin/stocktake_exporter.md
- Label Printing:
- Label Printer: plugins/builtin/inventree_label.md
- Label Machine: plugins/builtin/inventree_label_machine.md