This tool allows you to update stock quantities in InvenTree using data from a CSV file or manual input. It supports adding, removing, or updating stock quantities for specific parts and locations in bulk.
- Batch Processing: Use a CSV file to apply multiple stock changes at once.
- Interactive Mode: Enter stock changes manually with options for validation and editing.
- Flexible Notes: Add transaction notes for better traceability.
- Error Handling: Handles invalid inputs and provides clear feedback.
- Confirmation Options: Allows manual confirmation or auto-apply mode for seamless operations.
-
Python 3.x installed.
-
A YAML configuration file named
inventree_api_config.yamlwith the following format:server_address: "https://your-inventree-server-address.com"
-
Clone the repository or copy the script to your local environment.
-
Install required dependencies:
Required Python Packages - csv, requests, getpass, argparse, yaml
-
Ensure
inventree_api_config.yamlis present in the same directory as the script.
Run the script with the following options:
-u,--username: Specify the InvenTree username (required).-f,--file: Path to the CSV file containing stock changes.-n,--note: Add a note for all stock transactions in the session.-a,--auto-confirm: Skip confirmation for all changes (auto-apply).
- Using a CSV file for updates:
python script.py --username "your_username" --file "path to your .csv file" --note "Inventory adjustment"
- Manual stock update with interactive prompts:
python script.py --username "your_username"
For Windows, create a .bat file with the same name as the Python script (e.g., ivtr-stock-update.bat) with the following content:
@echo off
python ivtr-stock-update.py %*Save the file in the same directory as the Python script. Then, add the directory to the system path:
- Open System Properties
- Navigate to Advanced > Environment Variables > System Variables
- Edit the Path variable and add the script directory
- Save & Close
This allows running the script without the python prefix:
.\ivtr-stock-update.bat --username "your_username"
.\ivtr-stock-update.bat --username "your_username" --file "path to your .csv file"The CSV file should have the following columns in the specified order:
- IPN: Internal Part Number of the part to be updated.
- quantity: Quantity to add/remove (positive for addition, negative for removal).
- note: Optional note for the transaction.
Example:
IPN|quantity|note
12345|10|Restocking
12346|-5|Used in assembly- Loads server address from
inventree_api_config.yaml. - Prompts for the username and password to authenticate with InvenTree.
- Reads stock adjustments from the CSV file or manual input.
- Confirms changes before applying them unless auto-confirm is enabled.
- Applies stock adjustments.
- Invalid IPNs or quantities are flagged, and users are prompted to correct them.
- Up to 5 invalid attempts for both IPNs and quantities are allowed before the program exits.
- Ensure InvenTree is accessible and the provided credentials have appropriate permissions.
- Use auto-confirm mode with caution to avoid unintended changes.
This script is provided "as is" without warranty of any kind.