Pythonproject(final)
Pythonproject(final)
Mini Project
Subject: Skill Base Lab Course: Python Programming CSL405
A PROJECT REPORT ON
“Inventory Management System”
by
Small marts often struggle with inefficient inventory management due to reliance on manual processes
or outdated tools. Key challenges include:
• Time-Consuming Stock Updates: Staff must manually track stock levels, leading to delays
and errors during busy hours.
• Slow Billing Process: Adding or removing items one-by-one for customers at the counter is
cumbersome with traditional systems.
• Stock Visibility: Lack of real-time insights into low-stock items hinders restocking decisions.
• Scalability: Paper-based or basic digital solutions fail to adapt as the mart grows.
This project aims to address these issues by providing an automated, intuitive, and scalable stock
management solution tailored for small retail environments.
Design/Methodology:
The system was designed using a modular approach with Django’s MVT (Model-View-Template)
architecture, ensuring maintainability and scalability.
• System Architecture:
• Models: Three core database models—Category, Product, and Transaction—store and
manage inventory data in SQLite.
• Views: Python functions handle logic for dashboard display, bulk transactions, and
billing counter operations.
• Templates: HTML with Bootstrap 5 renders the UI, including a dashboard, bulk
transaction form, and billing counter grid.
• Key Features:
• Dashboard: Displays all products with stock levels, highlighting low-stock items (≤5
units) in red.
• Bulk Transaction: Allows staff to add/remove multiple units of a product (e.g.,
restocking).
• Billing Counter: Enables one-click sales and returns of single units, optimized for
speed during checkout.
Methodology:
• Development: Iterative process starting with basic CRUD operations, followed by UI
enhancements inspired by D-Mart’s clean, functional design.
• Testing: Manual testing on Ubuntu via Django’s development server (python3 manage.py
runserver) to ensure stock updates and UI responsiveness.
• Deployment Prep: Code structured for easy GitHub upload and local setup by others.
UI Design:
Operating System: Ubuntu (tested on 22.04 LTS, adaptable to other Linux distros).
Programming Language: Python 3.8+ (Django’s runtime), HTML/CSS for templates.
Frameworks/Libraries:
• Django 5.x.x (web framework).
• Bootstrap 5.3.3 (via CDN for styling).
import tkinter as tk
from tkinter import
messagebox, ttk
import sqlite3
# Initialize database
def initialize_database():
conn =
sqlite3.connect('mart_stock.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF
NOT EXISTS stock (
id INTEGER
PRIMARY KEY
AUTOINCREMENT,
item_name TEXT
NOT NULL,
quantity INTEGER,
category TEXT
)
''')
conn.commit()
conn.close()
# CRUD Functions
def create_item(item_name,
quantity, category):
conn =
sqlite3.connect('mart_stock.db')
cursor = conn.cursor()
cursor.execute("INSERT
INTO stock (item_name,
quantity, category) VALUES
(?, ?, ?)",
(item_name,
quantity, category))
conn.commit()
conn.close()
def read_items():
conn =
sqlite3.connect('mart_stock.db')
cursor = conn.cursor()
cursor.execute("SELECT *
FROM stock")
items = cursor.fetchall()
conn.close()
return items
def update_item(item_id,
item_name=None,
quantity=None,
category=None):
conn =
sqlite3.connect('mart_stock.db')
cursor = conn.cursor()
updates = {}
if item_name:
updates['item_name'] =
item_name
if quantity is not None:
updates['quantity'] = quantity
if category:
updates['category'] = category
if updates:
query = "UPDATE stock
SET " + ", ".join(f"{k} = ?" for
k in updates.keys()) + "
WHERE id = ?"
values =
list(updates.values()) +
[item_id]
cursor.execute(query,
values)
conn.commit()
conn.close()
def delete_item(item_id):
conn =
sqlite3.connect('mart_stock.db')
cursor = conn.cursor()
cursor.execute("DELETE
FROM stock WHERE id = ?",
(item_id,))
conn.commit()
conn.close()
# GUI Application
class StockManagerApp:
def __init__(self, root):
self.root = root
self.root.title("Mart Stock
Management System")
self.root.geometry("600x500")
# Initialize database
initialize_database()
# Title
tk.Label(root, text="Mart
Stock Manager", font=("Arial",
16, "bold")).pack(pady=10)
# Input Frame
input_frame =
tk.Frame(root)
input_frame.pack(pady=10)
tk.Label(input_frame,
text="Item Name:",
font=("Arial", 12)).grid(row=0,
column=0, padx=5)
self.item_entry =
tk.Entry(input_frame,
width=20, font=("Arial", 12))
self.item_entry.grid(row=0,
column=1, padx=5)
tk.Label(input_frame,
text="Quantity:", font=("Arial",
12)).grid(row=1, column=0,
padx=5)
self.quantity_entry =
tk.Entry(input_frame,
width=20, font=("Arial", 12))
self.quantity_entry.grid(row=1,
column=1, padx=5)
tk.Label(input_frame,
text="Category:",
font=("Arial", 12)).grid(row=2,
column=0, padx=5)
self.category_var =
tk.StringVar(value="General")
categories = ["General",
"Food", "Electronics",
"Clothing"]
self.category_menu =
ttk.Combobox(input_frame,
textvariable=self.category_var,
values=categories,
state="readonly")
self.category_menu.grid(row=2
, column=1, padx=5)
# Buttons
tk.Button(input_frame,
text="Add Item",
command=self.add_item,
bg="green",
fg="white").grid(row=3,
column=0, pady=5)
tk.Button(input_frame,
text="Update Selected",
command=self.update_item,
bg="blue",
fg="white").grid(row=3,
column=1, pady=5)
tk.Button(input_frame,
text="Delete Selected",
command=self.delete_item,
bg="red",
fg="white").grid(row=3,
column=2, pady=5)
# Stock List
self.tree =
ttk.Treeview(root,
columns=("ID", "Name",
"Quantity", "Category"),
show="headings", height=10)
self.tree.heading("ID",
text="ID")
self.tree.heading("Name",
text="Item Name")
self.tree.heading("Quantity",
text="Quantity")
self.tree.heading("Category",
text="Category")
self.tree.column("ID",
width=50)
self.tree.column("Name",
width=200)
self.tree.column("Quantity",
width=100)
self.tree.column("Category",
width=150)
self.tree.pack(pady=10)
self.refresh_list()
def refresh_list(self):
for item in
self.tree.get_children():
self.tree.delete(item)
for item in read_items():
self.tree.insert("",
"end", values=item)
def add_item(self):
item_name =
self.item_entry.get().strip()
quantity =
self.quantity_entry.get().strip()
category =
self.category_var.get()
if not item_name or not
quantity.isdigit():
messagebox.showerror("Error
", "Please enter a valid item
name and quantity.")
return
create_item(item_name,
int(quantity), category)
self.refresh_list()
self.clear_entries()
messagebox.showinfo("Succes
s", f"Added '{item_name}' to
stock.")
def update_item(self):
selected =
self.tree.selection()
if not selected:
messagebox.showerror("Error",
"Please select an item to
update.")
return
item_id =
self.tree.item(selected[0])["valu
es"][0]
item_name =
self.item_entry.get().strip() or
None
quantity =
self.quantity_entry.get().strip()
quantity = int(quantity) if
quantity.isdigit() else None
category =
self.category_var.get() or None
update_item(item_id,
item_name, quantity, category)
self.refresh_list()
self.clear_entries()
messagebox.showinfo("Succes
s", f"Updated item ID
{item_id}.")
def delete_item(self):
selected =
self.tree.selection()
if not selected:
messagebox.showerror("Error",
"Please select an item to
delete.")
return
item_id =
self.tree.item(selected[0])["valu
es"][0]
item_name =
self.tree.item(selected[0])["valu
es"][1]
if
messagebox.askyesno("Confir
m Delete", f"Delete
'{item_name}' (ID:
{item_id})?"):
delete_item(item_id)
self.refresh_list()
messagebox.showinfo("Succes
s", f"Deleted '{item_name}'.")
def clear_entries(self):
self.item_entry.delete(0,
tk.END)
self.quantity_entry.delete(0,
tk.END)
self.category_var.set("General"
)
if __name__ == "__main__":
root = tk.Tk()
app =
StockManagerApp(root)
root.mainloop()
Snapshoot of Output (Result) :
Fig. Dashboard