-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory_management.py
More file actions
126 lines (83 loc) · 2.05 KB
/
Copy pathinventory_management.py
File metadata and controls
126 lines (83 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import sqlite3
conn = sqlite3.connect("inventory.db")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS products(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
quantity INTEGER NOT NULL,
price REAL NOT NULL
)
""")
conn.commit()
def add_product():
name = input("Product Name: ")
quantity = int(input("Quantity: "))
price = float(input("Price: "))
cursor.execute("""
INSERT INTO products(name, quantity, price)
VALUES (?, ?, ?)
""", (name, quantity, price))
conn.commit()
print("Product Added Successfully")
def view_products():
cursor.execute("SELECT * FROM products")
products = cursor.fetchall()
print("\n===== Inventory =====")
for p in products:
print(
f"ID:{p[0]} | "
f"Name:{p[1]} | "
f"Qty:{p[2]} | "
f"Price:₹{p[3]}"
)
def update_stock():
pid = int(input("Product ID: "))
qty = int(input("New Quantity: "))
cursor.execute("""
UPDATE products
SET quantity=?
WHERE id=?
""", (qty, pid))
conn.commit()
print("Stock Updated")
def delete_product():
pid = int(input("Product ID: "))
cursor.execute(
"DELETE FROM products WHERE id=?",
(pid,)
)
conn.commit()
print("Product Deleted")
def low_stock():
cursor.execute("""
SELECT * FROM products
WHERE quantity < 10
""")
items = cursor.fetchall()
print("\nLow Stock Products")
for p in items:
print(p)
while True:
print("\n1.Add Product")
print("2.View Products")
print("3.Update Stock")
print("4.Delete Product")
print("5.Low Stock Report")
print("6.Exit")
choice = input("Choice: ")
if choice == "1":
add_product()
elif choice == "2":
view_products()
elif choice == "3":
update_stock()
elif choice == "4":
delete_product()
elif choice == "5":
low_stock()
elif choice == "6":
break
else:
print("Invalid Choice")
conn.close()