Menu

Post image 1
Post image 2
1 / 2
0

Python Inventory Tracker: Automatic Low-Stock Alerts in 50 Lines

DEV Community·Brad·18 days ago
#reeMufhZ
Reading 0:00
15s threshold

Python Inventory Tracker: Automatic Low-Stock Alerts in 50 Lines Manual inventory tracking breaks down fast. This script tracks stock in SQLite and alerts you before you run out. import sqlite3 from datetime import datetime class InventoryTracker : def __init__ ( self ): self . db = sqlite3 . connect ( ' inventory.db ' ) self . db . execute ( ''' CREATE TABLE IF NOT EXISTS stock (id INTEGER PRIMARY KEY, name TEXT, qty INTEGER, reorder INTEGER, cost REAL) ''' ) self . db . commit () def add ( self , name , qty , reorder_at , unit_cost ): self . db . execute ( ' INSERT INTO stock VALUES (NULL,?,?,?,?) ' , ( name , qty , reorder_at , unit_cost )) self . db . commit () def consume ( self , item_id , amount ): self . db . execute ( ' UPDATE stock SET qty = qty - ? WHERE id = ? ' , ( amount , item_id )) self . db . commit () row = self . db . execute ( ' SELECT name, qty, reorder FROM stock WHERE id=? ' , ( item_id ,)).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More