Skip to content

Latest commit

 

History

History
100 lines (78 loc) · 3.54 KB

File metadata and controls

100 lines (78 loc) · 3.54 KB

InvenTree Stock Adjustment Tool

Overview

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.

Features

  • 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.

Prerequisites

  • Python 3.x installed.

  • A YAML configuration file named inventree_api_config.yaml with the following format:

    server_address: "https://your-inventree-server-address.com"

Installation

  1. Clone the repository or copy the script to your local environment.

  2. Install required dependencies:

    Required Python Packages - csv, requests, getpass, argparse, yaml

  3. Ensure inventree_api_config.yaml is present in the same directory as the script.

Usage

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).

Examples

  1. Using a CSV file for updates:
    python script.py --username "your_username" --file "path to your .csv file" --note "Inventory adjustment"
  2. Manual stock update with interactive prompts:
    python script.py --username "your_username"

Using without python prefix

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:

  1. Open System Properties
  2. Navigate to Advanced > Environment Variables > System Variables
  3. Edit the Path variable and add the script directory
  4. 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"

CSV Format

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

Script Workflow

  1. Loads server address from inventree_api_config.yaml.
  2. Prompts for the username and password to authenticate with InvenTree.
  3. Reads stock adjustments from the CSV file or manual input.
  4. Confirms changes before applying them unless auto-confirm is enabled.
  5. Applies stock adjustments.

Error Handling

  • 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.

Notes

  • Ensure InvenTree is accessible and the provided credentials have appropriate permissions.
  • Use auto-confirm mode with caution to avoid unintended changes.

License

This script is provided "as is" without warranty of any kind.