Categories We Write About

Build an inventory tracker

Building an inventory tracker involves creating a system that helps manage and monitor stock levels, product movements, and reorder points. Below is a comprehensive guide and sample implementation of a basic inventory tracker, suitable for a small business or personal use. The example will include key features like adding items, updating stock, viewing inventory, and tracking product details.


Key Features of an Inventory Tracker

  • Add new items to inventory

  • Update stock quantities (increase/decrease)

  • View current inventory status

  • Search for specific items

  • Track item details like name, SKU, quantity, price, and reorder level

  • Alerts for low stock (optional)


Technology Choices

You can build an inventory tracker in many ways:

  • Spreadsheet (Excel, Google Sheets) — simplest form

  • Desktop app (Python, C#, Java)

  • Web app (JavaScript, PHP, Python with Flask/Django, Node.js)

  • Database integration for larger scale

For demonstration, here’s a simple inventory tracker built with Python using a CSV file as a data store, which is easy to run and expand.


Inventory Tracker in Python

python
import csv import os INVENTORY_FILE = 'inventory.csv' # Ensure inventory file exists with headers def initialize_inventory(): if not os.path.isfile(INVENTORY_FILE): with open(INVENTORY_FILE, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(['SKU', 'Name', 'Quantity', 'Price', 'ReorderLevel']) # Add a new item to inventory def add_item(): sku = input("Enter SKU (unique code): ").strip() name = input("Enter product name: ").strip() quantity = int(input("Enter quantity: ")) price = float(input("Enter price per unit: ")) reorder_level = int(input("Enter reorder level: ")) # Check if SKU already exists inventory = load_inventory() if sku in inventory: print("Error: SKU already exists.") return with open(INVENTORY_FILE, mode='a', newline='') as file: writer = csv.writer(file) writer.writerow([sku, name, quantity, price, reorder_level]) print(f"Item '{name}' added successfully.") # Load inventory into a dict keyed by SKU def load_inventory(): inventory = {} with open(INVENTORY_FILE, mode='r') as file: reader = csv.DictReader(file) for row in reader: sku = row['SKU'] inventory[sku] = { 'Name': row['Name'], 'Quantity': int(row['Quantity']), 'Price': float(row['Price']), 'ReorderLevel': int(row['ReorderLevel']) } return inventory # Update stock quantity (increase or decrease) def update_stock(): sku = input("Enter SKU to update: ").strip() inventory = load_inventory() if sku not in inventory: print("SKU not found.") return print(f"Current quantity for {inventory[sku]['Name']}: {inventory[sku]['Quantity']}") change = int(input("Enter quantity to add (+) or remove (-): ")) new_quantity = inventory[sku]['Quantity'] + change if new_quantity < 0: print("Error: Quantity cannot be negative.") return inventory[sku]['Quantity'] = new_quantity save_inventory(inventory) print(f"Updated quantity for {inventory[sku]['Name']} is now {new_quantity}.") # Save inventory back to CSV def save_inventory(inventory): with open(INVENTORY_FILE, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(['SKU', 'Name', 'Quantity', 'Price', 'ReorderLevel']) for sku, data in inventory.items(): writer.writerow([sku, data['Name'], data['Quantity'], data['Price'], data['ReorderLevel']]) # Display current inventory with low stock alert def view_inventory(): inventory = load_inventory() print(f"{'SKU':<10} {'Name':<20} {'Quantity':<10} {'Price':<10} {'Reorder Level':<15} {'Status'}") print("-" * 70) for sku, data in inventory.items(): status = "OK" if data['Quantity'] <= data['ReorderLevel']: status = "LOW STOCK" print(f"{sku:<10} {data['Name']:<20} {data['Quantity']:<10} {data['Price']:<10.2f} {data['ReorderLevel']:<15} {status}") # Search for an item by SKU or Name def search_item(): term = input("Enter SKU or Name to search: ").strip().lower() inventory = load_inventory() found = False for sku, data in inventory.items(): if term in sku.lower() or term in data['Name'].lower(): print(f"SKU: {sku}, Name: {data['Name']}, Quantity: {data['Quantity']}, Price: {data['Price']}, Reorder Level: {data['ReorderLevel']}") found = True if not found: print("No matching items found.") # Main menu loop def main(): initialize_inventory() while True: print("nInventory Tracker Menu") print("1. Add Item") print("2. Update Stock") print("3. View Inventory") print("4. Search Item") print("5. Exit") choice = input("Choose an option: ").strip() if choice == '1': add_item() elif choice == '2': update_stock() elif choice == '3': view_inventory() elif choice == '4': search_item() elif choice == '5': print("Exiting Inventory Tracker.") break else: print("Invalid choice, try again.") if __name__ == "__main__": main()

Explanation

  • The script uses a CSV file to store inventory data persistently.

  • It initializes the CSV file with headers if it doesn’t exist.

  • Users can add new items, update quantities (stock in/out), and view all inventory with alerts on low stock.

  • Search functionality helps find items by SKU or name.

  • Data validation ensures no negative stock or duplicate SKUs.


How to Use

  • Save the script as inventory_tracker.py.

  • Run it in a Python environment.

  • Follow menu prompts to manage inventory.


Extending the Tracker

  • Add date/time logs for stock changes.

  • Integrate with barcode scanning.

  • Use a database (SQLite, MySQL) for scalability.

  • Build a GUI or web interface.

  • Automate reorder alerts via email.


This simple yet functional inventory tracker can be your starting point to a more advanced system as your needs grow. If you want, I can help you build a web-based or database-driven version next!

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About