A beginner-friendly, lightweight Flask app to generate shopping bills with simple smart discounts. Uses SQLite for storage, plain HTML/CSS for the UI, and Python for backend logic.
- Enter up to 5 items (name, quantity, price)
- Automatic discounts:
- 2% per-item discount if quantity >= 10
- 10% cart discount if subtotal after item discounts > 1000
- Extra 5% cart discount if 5 or more distinct items
- View the generated bill and recent bill history
- Backend: Python (Flask)
- Frontend: HTML, CSS
- Database: SQLite (file
billmate/billmate.dbauto-created)
# 1) (Recommended) create and activate a virtual environment
python3 -m venv .venv && source .venv/bin/activate # macOS/Linux
# or on Windows PowerShell:
# py -m venv .venv; .venv\Scripts\Activate.ps1
# 2) Install dependencies
pip install -r requirements.txt
# 3) Run the app
python billmate/app.py
# Alternatively, use the helper scripts from project root:
./run.sh # macOS/Linux
run.bat # Windows- Create and activate a virtual environment (recommended)
- macOS/Linux
python3 -m venv .venv source .venv/bin/activate - Windows (PowerShell)
py -m venv .venv .venv\\Scripts\\Activate.ps1
- macOS/Linux
- Install dependencies
pip install -r requirements.txt
- Create your environment file (optional but recommended)
cp .env.example .env # then edit .env to adjust SECRET_KEY / HOST / PORT / DEBUG - Run the app
# Option A: from root python billmate/app.py # Option B: helper scripts from root ./run.sh # macOS/Linux run.bat # Windows
- Open your browser at http://127.0.0.1:5000 (or your HOST:PORT if changed)
billmate/
app.py
billmate.db (auto-created)
requirements.txt
templates/
base.html
index.html
bill.html
history.html
static/
styles.css
- The code uses straightforward SQLite statements without an ORM to remain easy to follow.
- If you want to reset data, delete the
billmate.dbfile (with the app stopped). - For production use, you would want more robust validation, authentication, and deployment setup.
You can run directly, or set up a one-click debug configuration.
-
Manual run via VS Code Terminal:
- Open the folder in VS Code.
- Select your virtual environment as the Python interpreter.
- Terminal > New Terminal, then:
source .venv/bin/activate # macOS/Linux # or: .venv\\Scripts\\Activate.ps1 # Windows PowerShell python billmate/app.py
-
One-click launch (optional): create
.vscode/launch.jsonwith:{ "version": "0.2.0", "configurations": [ { "name": "BillMate (Launch)", "type": "python", "request": "launch", "program": "${workspaceFolder}/billmate/app.py", "console": "integratedTerminal", "envFile": "${workspaceFolder}/.env" } ] }
Then press F5 to start the app with variables from .env.
Configure via .env (loaded by python-dotenv). Defaults are safe for local use.
SECRET_KEY— Flask session key (use a strong secret in non-dev).HOST— default127.0.0.1.PORT— default5000.DEBUG—true/false(defaulttrue).
- Requires Python 3.8+ (Flask 3.x requirement).
- Works on macOS, Windows, and Linux.
- Uses SQLite; the database file is created at
billmate/billmate.dbautomatically.
- Port already in use: change
PORTin.env, or stop the other process. - Env not loading: ensure
python-dotenvis installed and.envis at the project root. - DB locked errors: stop the app and retry; SQLite allows a single writer.