Introduction
Every shop needs to know what is in stock, what it is worth and what to reorder. This tracker keeps a movement history for each item so every change can be explained.
Problem statement
Objectives
- Model items with a dataclass and computed properties
- Validate quantities and prices
- Keep an audit trail of changes
- Sort and filter for reports
Features
- Stock in/out with notes
- Price changes recorded in history
- Reorder warnings and a low-stock report
- Inventory value report
- Movement history per SKU
Concepts demonstrated
- Audit trails
- Validation
- Computed properties
- Report formatting
System architecture
Item stores quantity, price, reorder level and a list of movement strings; value and low are properties. Inventory.move validates the quantity and stock level before changing anything and appends a history entry. table prints a list of items; run dispatches commands.
Folder structure
Complete source code
main.py
What each file does
- main.py
- The Item dataclass, the Inventory service with stock movements, the reports and the command loop.
How to run it
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
add P100 Gel_Pen 120 15 40 add N200 A4_Notebook 60 45.50 25 add S300 Stapler 12 180 5 add P100 Duplicate 1 1 1 add E400 Eraser ten 5 20 out P100 90 school order out N200 70 out N200 40 walk-in in S300 3 supplier price S300 199 out S300 11 in Z999 5 low report history P100 quit
Testing
- Run
python main.py < tests/sample-input.txtand compare withtests/expected-output.txt. - A duplicate SKU and the quantity 'ten' are rejected.
- Removing 70 notebooks fails because only 60 are in stock.
- After the movements all three items are at or below their reorder level, and the stock is worth 2,156.00.
Common errors
Stock goes negative
Check the requested quantity against the current stock before subtracting.
Underscores appear in item names
Replace underscores with spaces when adding, as add() does.
Possible improvements
- Load and save inventory as CSV
- Track suppliers and purchase orders
- Report the best-selling items by quantity sold
Additional challenges
- 1Add an 'adjust <sku> <qty> <reason>' command for stock counts.
- 2Compute how many days of stock remain from average daily sales.
- 3Support item categories and a value report per category.
Built and tested it yourself? Mark it to update your dashboard.