Inventory Management System
Inventory Management System with Source Code is a Python program that can store and purchase an item.
The sole purpose of the system is to manage and organize the list of all items and enable you to purchase the
ordered item.
The project is a console application where you can access by entering certain alphabet keys. The system can
make the management and client transactions more efficient and faster. By using the system, it can make
your transaction convenient and reliable for storing the item data. The system uses a text file to store the list
of all items and automatically display the list when the application is launched. The system also has add-to-
cart features that let you store your temporary item as you order.
This program was created using only Python language and mySQL as database.
Inventory Management System Project in Python Features:
Add an item Menu
This is where you can manage the information of an item. You can add a new item by
entering the Item Number, Description, and Price.
Remove an item Menu
From here you can remove a certain item by entering an Item Number of that item
Remove specifics of an item Menu
This is where you can update the details of certain items.
List all items Menu
From here you can view all available items on the list.
Inquire about an item Menu
In this menu, you check the full details of an individual item.
Purchase Menu
From here you can purchase an item and add them to a shopping cart.
Checkout Menu
From here you can checkout your ordered item from the shopping cart.
Database Schemas:
Inventory table:
CREATE TABLE `localdb`.`inventory` (
`PartNumber` INT NOT NULL,
`Description` VARCHAR(200) NOT NULL,
`Price` DECIMAL(3,2) NOT NULL,
`Stock` INT NOT NULL,
PRIMARY KEY (`PartNumber`));
PurchaseHistory table:
CREATE TABLE `localdb`.`purchasehistory` (
`CustomerNumber` INT NOT NULL,
`PartNumber` INT NOT NULL,
`Description` VARCHAR(300) NOT NULL,
`UnitPrice` DECIMAL(3,2) NOT NULL,
`Quantity` INT NOT NULL,
`PurchaseDate` DATETIME NOT NULL);
Code:
#Inventory Management System
import [Link]
from datetime import datetime
cnx = [Link](user='root', password='Pass0rd',
host='localhost',
database='localdb')
c="y" #Runs the while loop as long as user wants
#Instructions
print("Welcome to IMS")
print()
print("A-Add an item")
print("R-Remove an item")
print("E-Edit specifics of an item")
print("L-List all items")
print("I-Inquire about a part")
print("P-Purchase")
print("Q-Quit")
print("remove-Remove an item from the cart")
print("help-See all commands again")
print()
while(c!= "q" or c!= "Q"):
c= input("What would you like to do? ")
if(c=="q" or c=="Q"):
break
elif(c=="A" or c=="a"):#Add a part
p_no = int(input("Enter part number: "))
p_desc = input("Enter part description: ")
p_pr = float(input("Enter part price: "))
p_stock = int(input("Enter part stock: "))
cursor = [Link]()
[Link]("SELECT COUNT(1) FROM inventory WHERE PartNumber = %s",(p_no,))
if [Link]()[0]:
print()
print("That part number already exists.")
else:
if(p_stock < 0):
p_stock = 0
print()
print("The stock of an item cannot be negative, the stock has been set to 0.")
cursor = [Link]()
[Link]("INSERT INTO inventory (PartNumber, Description, Price , Stock) VALUES (%s,
%s, %s, %s)",(p_no, p_desc, p_pr, p_stock))
[Link]()
print("Part number: ",p_no," Description: ",p_desc," Price: ",p_pr," Stock: ",p_stock)
print("Inventory was added successfully!")
print()
elif(c=="E" or c=="e"):#Edit a part
print()
p_no = int(input("Enter part number: "))
cursor = [Link]()
[Link]("SELECT COUNT(1) FROM inventory WHERE PartNumber = %s",(p_no,))
if [Link]()[0]:
p_desc = input("Enter part description: ")
p_pr = float(input("Enter part price: "))
p_stock = int(input("Enter part stock: "))
cursor = [Link]()
[Link]("UPDATE inventory SET Description=%s, Price=%s, Stock=%s WHERE
PartNumber=%s",(p_desc, p_pr, p_stock,p_no))
[Link]()
print()
print("Part number: ",p_no," Description: ",p_desc," Price: ",p_pr," Stock: ",p_stock)
print("Inventory was Updated successfully!")
else:
print()
print("That item does not exist, to add an item use A")
print()
elif(c=="R" or c=="r"):#Remove a part
print()
p_no = int(input("Enter part number: "))
cursor = [Link]()
[Link]("SELECT COUNT(1) FROM inventory WHERE PartNumber = %s",(p_no,))
if [Link]()[0]:
are_you_sure = input("Are you sure you want to remove that item(y/n)? ")
if(are_you_sure=="y" or are_you_sure=="Y"):
cursor = [Link]()
[Link]("DELETE FROM inventory WHERE PartNumber=%s",(p_no,))
[Link]()
print()
print("Item successfully removed!")
else:
print()
print("Sorry, we don't have such an item!")
print()
elif(c=="L" or c=="l"):#List all the parts
print()
cursor = [Link]()
[Link]("SELECT COUNT(1) FROM inventory")
if [Link]()[0]:
cursor = [Link]()
[Link]("SELECT * FROM inventory")
results = [Link]()
widths = [0]*len(results[0]) # Assuming there is always one row
for row in results:
widths = [max(w,len(str(c))) for w,c in zip(widths,row)]
columns = []
tavnit = '|'
separator = '+'
colIndex = 0
for cd in [Link]:
if len(cd[0])> widths[colIndex]:
widths[colIndex] = len(cd[0])
[Link](cd[0])
colIndex = colIndex+1
for w in widths:
tavnit += " %-"+"%ss |" % (w,)
separator += '-'*w + '--+'
print(separator)
print(tavnit % tuple(columns))
print(separator)
for row in results:
print(tavnit % row)
print(separator)
else:
print()
print("Inventory is empty, to add an item use A")
print()
elif(c=="I" or c=="i"):#Inquire about a part
print()
p_no = int(input("Enter part number: "))
cursor = [Link]()
[Link]("SELECT * FROM inventory WHERE PartNumber = %s",(p_no,))
row = [Link]()
if [Link]:
print()
print("Part number: ",row[0]," Description: ",row[1]," Price: ",row[2]," Stock: ",row[3])
else:
print()
print("Sorry, we don't have such an item!")
print()
elif(c=="P" or c=="p"):#Purchase items
print()
cust_no=input("Enter customer number: ")
print()
p=input("Enter Part number (or C for checkout/R for removing an item from cart): ")
cart={}
total_cost=0
while(p!="c" and p!='C'):
if(p=='r' or p=='R'):
p_no_to_remove=int(input("Enter Part number to remove: "))
if(p_no_to_remove in cart):
item=[Link](p_no_to_remove)
total_cost = total_cost - item[1]*q
j=0
for i in range(0,len(cart)):#To find the index of the part in the list cart
if(i==p_no_to_remove):
j=i
[Link](j)
print()
print(item[0],"removed from cart: ")
else:
print()
print("Item not in cart")
else:
p_no=int(p)
cursor = [Link]()
[Link]("SELECT * FROM inventory WHERE PartNumber = %s",(p_no,))
row = [Link]()
if [Link]:
stock_current = row[3]
q=int(input("Enter Quantity: "))
if(stock_current - q)>0:
total_cost = total_cost + row[2]*q
if(p_no in cart):
item=[Link](p_no)
item[2] = item[2]+q
[Link]({p_no: item})
else:
[Link]({p_no: [row[1],row[2],q]})
print("Item added to cart")
else:
print()
print("Sorry, item is low in stock!")
else:
print()
print("Sorry, we don't have such an item!")
print()
p=input("Enter Part number (or C for checkout/R for removing an item from cart): ")
print()
print("You bought the following items: ")
print()
widths=[len("PartNumber"), len("Description"),len("UnitPrice"), len("Quantity"),len("Price")]
columns = ["PartNumber", "Description","UnitPrice", "Quantity","Price"]
purchaseDetails=[]
cartPrintDetails=[]
for pno in cart:
cartitem=[Link](pno)
[Link]((pno,cartitem[0],cartitem[1],cartitem[2],cartitem[1]*cartitem[2]))
[Link]((cust_no, pno,cartitem[0],cartitem[1],cartitem[2],[Link]()))
widths[0] = max(widths[0], len(str(pno)))
widths[1] = max(widths[1], len(str(cartitem[0])))
widths[2] = max(widths[2], len(str(cartitem[1])))
widths[3] = max(widths[3], len(str(cartitem[2])))
widths[4] = max(widths[4], len(str(cartitem[1]*cartitem[2])))
tavnit = '|'
separator = '+'
for w in widths:
tavnit += " %-"+"%ss |" % (w,)
separator += '-'*w + '--+'
print(separator)
print(tavnit % tuple(columns))
print(separator)
for row in cartPrintDetails:
print(tavnit % row)
print(separator)
print("Total: ","$",round(total_cost,2))
p=input("Proceed to payment (y/n): ")
if(p=='y' or p=='Y'):
cursor = [Link]()
[Link]("INSERT INTO PurchaseHistory (CustomerNumber, PartNumber, Description,
UnitPrice, Quantity, PurchaseDate) VALUES(%s, %s, %s, %s, %s, %s)",purchaseDetails)
[Link]()
print("Thank you for shopping")
print()
elif(c=="help"):#Display all commands
print()
print("Help Centre")
print("A-Add an item")
print("R-Remove an item")
print("E-Edit specifics of an item")
print("L-List all items")
print("I-Inquire about a part")
print("P-Purchase")
print("help-See all commands again")
print("If you have any other questions or concerns please contact the manager.")
print()
else:
print()
print("ERROR! Contact manager for help!")
print()
print()
print("Thank you for using IMS")
Outputs: