Introduction
Inventory management is a critical component of any business, ensuring that stock levels are adequately maintained to meet customer demand while minimizing costs. The Inventory Management System (IMS) is a Python-based solution designed to efficiently manage inventory data, utilizing CSV files for persistent storage, Pandas for data manipulation, and Matplotlib for visualization.
Objectives
- Simplify the process of managing inventory.
- Provide functionalities to add, update, delete, and search products.
- Ensure data persistence using CSV files.
- Generate reports for analyzing stock levels.
System Features
1. Add Product
Allows the user to add new products to the inventory by specifying:
- Product Name
- Quantity
- Price
2. Update Product
Provides functionality to update details of existing products:
- Modify quantity
- Update price
3. View Inventory
Displays the complete list of products in the inventory along with their details:
- Product Name
- Quantity
- Price
4. Delete Product
Enables users to remove products from the inventory by specifying the product name.
5. Search Functionality
Searches the inventory for products matching a user-specified name, with support for partial matches.
6. Generate Reports
Creates a statistical summary of the inventory and visualizes stock levels using bar charts for better insights.
7. Database Integration
The system uses a CSV file as a database for storing product details persistently. The CSV file includes the following columns:
- Product Name
- Quantity
- Price
Technologies Used
- Python Libraries:
- Pandas: For data manipulation and management.
- Matplotlib: For generating visual reports.
- CSV:
- Acts as the database for storing product details.
Code Structure
Modules and Classes
- InventoryManagementSystem Class:
- Methods for handling CRUD (Create, Read, Update, Delete) operations.
- Methods for data visualization and reporting.
Main Script
The main script provides a user-friendly menu-driven interface for interacting with the system.
File Structure
inventory.csv
: Stores product data persistently.(Download)inventory_management.py
: Contains the main implementation of the Inventory Management System.(Download .py file)
Complete Code
import pandas as pd
import matplotlib.pyplot as plt
import os
class InventoryManagementSystem:
def __init__(self, csv_file='inventory.csv'):
self.csv_file = csv_file
if not os.path.exists(self.csv_file):
# Create the CSV file with headers if it doesn't exist
pd.DataFrame(columns=['Product Name', 'Quantity', 'Price']).to_csv(self.csv_file, index=False)
def load_inventory(self):
return pd.read_csv(self.csv_file)
def save_inventory(self, df):
df.to_csv(self.csv_file, index=False)
def add_product(self, name, quantity, price):
inventory = self.load_inventory()
new_product = pd.DataFrame([{ 'Product Name': name, 'Quantity': quantity, 'Price': price }])
inventory = pd.concat([inventory, new_product], ignore_index=True)
self.save_inventory(inventory)
print(f"Product '{name}' added successfully!")
def update_product(self, name, quantity=None, price=None):
inventory = self.load_inventory()
if name in inventory['Product Name'].values:
if quantity is not None:
inventory.loc[inventory['Product Name'] == name, 'Quantity'] = quantity
if price is not None:
inventory.loc[inventory['Product Name'] == name, 'Price'] = price
self.save_inventory(inventory)
print(f"Product '{name}' updated successfully!")
else:
print(f"Product '{name}' not found in inventory.")
def view_inventory(self):
inventory = self.load_inventory()
print("\nCurrent Inventory:")
print(inventory)
def delete_product(self, name):
inventory = self.load_inventory()
if name in inventory['Product Name'].values:
inventory = inventory[inventory['Product Name'] != name]
self.save_inventory(inventory)
print(f"Product '{name}' deleted successfully!")
else:
print(f"Product '{name}' not found in inventory.")
def search_product(self, name):
inventory = self.load_inventory()
results = inventory[inventory['Product Name'].str.contains(name, case=False)]
if not results.empty:
print("\nSearch Results:")
print(results)
else:
print(f"No products found with name containing '{name}'.")
def generate_report(self):
inventory = self.load_inventory()
print("\nInventory Report:")
print(inventory.describe())
plt.figure(figsize=(10, 6))
plt.bar(inventory['Product Name'], inventory['Quantity'], color='skyblue')
plt.xlabel('Product Name')
plt.ylabel('Quantity')
plt.title('Inventory Stock Levels')
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
plt.show()
if __name__ == "__main__":
ims = InventoryManagementSystem()
while True:
print("\nInventory Management System")
print("1. Add Product")
print("2. Update Product")
print("3. View Inventory")
print("4. Delete Product")
print("5. Search Product")
print("6. Generate Report")
print("7. Exit")
choice = input("Enter your choice: ")
if choice == '1':
name = input("Enter product name: ")
quantity = int(input("Enter quantity: "))
price = float(input("Enter price: "))
ims.add_product(name, quantity, price)
elif choice == '2':
name = input("Enter product name to update: ")
quantity = input("Enter new quantity (leave blank to skip): ")
price = input("Enter new price (leave blank to skip): ")
ims.update_product(name, int(quantity) if quantity else None, float(price) if price else None)
elif choice == '3':
ims.view_inventory()
elif choice == '4':
name = input("Enter product name to delete: ")
ims.delete_product(name)
elif choice == '5':
name = input("Enter product name to search: ")
ims.search_product(name)
elif choice == '6':
ims.generate_report()
elif choice == '7':
print("Exiting Inventory Management System. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
Implementation
Steps to Execute the Project:
- Ensure Python is installed on your system.
- Install required libraries:
pip install pandas matplotlib
- Run the script
inventory_management.py
. - Use the menu-driven interface to perform operations such as adding, updating, viewing, deleting, searching, and generating reports.
Example Outputs
Inventory View Example:
Product Name Quantity Price
Product A 100 10.50
Product B 50 20.75
Search Result Example:
Product Name Quantity Price
Product A 100 10.50
Report Visualization:
A bar chart displaying stock levels for each product.
Advantages
- User-friendly interface.
- Persistent storage with CSV.
- Visual representation of stock levels.
- Easy to maintain and extend functionality.
Future Enhancements
- Implement user authentication for secure access.
- Support for database integration (e.g., SQLite or MySQL).
- Enhanced reporting with additional visualizations and filters.
- Integration with e-commerce platforms for real-time inventory management.
Conclusion
The Inventory Management System provides an effective and efficient solution for managing inventory, with robust features for data handling and visualization. Its modular design ensures ease of use, maintenance, and scalability, making it suitable for small to medium-sized businesses.
Leave a Reply