Retail POS is a server-rendered Django point-of-sale and retail management system for small and medium businesses. It keeps sales, payments, inventory, returns, purchasing, expenses, register activity, customer and supplier balances, and audit history in one transactional application.
- Responsive cashier POS with product search/barcode input, weighted quantities, item and order discounts, tax, customer selection, notes, mixed tenders, change, and duplicate-submit protection
- Immutable completed sales with historical product, price, cost, tax, and discount snapshots
- 80 mm thermal receipts and A4 invoices with print views and authenticated, self-contained offline HTML downloads
- Per-location inventory ledger, stock adjustments, low-stock warnings, weighted-average cost, cost revaluation, and reconciliation tooling
- Register opening/closing, expected-versus-counted cash, cash in/out, sales, refunds, and variance tracking
- Full and partial sale returns, manager approval, refund records, inventory restoration, and conservative on-account refund protection
- Customers, purchase history, account ledger, outstanding balance, store credit, and payments
- Suppliers, purchase orders, partial goods receipts, supplier invoices, payments, allocations, goods returns, supplier credits, AP refund receivables, invoice corrections, payment reversals, and balances
- Posted/voided expenses, private validated receipt attachments, categories, and date filters
- Employee management with Admin, Manager, and Cashier roles and location scope
- Operational dashboard, Chart.js trends, low stock, recent sales, top products, payment mix, profit metrics, filterable reports, and safe CSV exports
- Append-only audit events for authentication and sensitive business operations
- Split local/test/production settings, environment-driven secrets, fail-closed PostgreSQL production configuration, security headers, CSRF, Argon2 passwords, and login throttling
The detailed model, transaction, permission, and reporting decisions are in docs/implementation-plan.md.
- Python 3.12
- Django 5.2 LTS
- PostgreSQL 17 for production and concurrency verification
- SQLite for initial local development
- Django templates, Bootstrap 5, vanilla JavaScript, and Chart.js
Decimal-based money and quantity calculations- pytest/pytest-django and Ruff
Open PowerShell in the repository root:
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txtLocal settings use SQLite and have safe development defaults. Environment variables are still recommended:
$env:DJANGO_SETTINGS_MODULE = "config.settings.local"
$env:SECRET_KEY = "replace-with-a-long-random-development-key"
$env:TIME_ZONE = "Africa/Casablanca"Build the database, synchronize the managed role groups, and create the repeat-safe demo:
python manage.py migrate
python manage.py bootstrap_roles
python manage.py seed_demoStart Django:
python manage.py runserverOpen:
- Dashboard: http://127.0.0.1:8000/
- Direct dashboard: http://127.0.0.1:8000/reports/dashboard/
- Point of sale: http://127.0.0.1:8000/sales/pos/
- Support admin: http://127.0.0.1:8000/admin/
seed_demo creates these users:
| Role | Username | Password |
|---|---|---|
| Admin | demo.admin |
RetailDemo!2026 |
| Manager | demo.manager |
RetailDemo!2026 |
| Cashier | demo.cashier |
RetailDemo!2026 |
These credentials are only for local development. The command refuses to run
when DEBUG=False. Never expose the demo database, and replace all demo
passwords before using its data outside a local environment.
Running seed_demo again repairs/reuses the demo records instead of duplicating
financial activity.
# Apply schema changes
python manage.py migrate
# Resynchronize Admin, Manager, and Cashier group permissions
python manage.py bootstrap_roles
# Check inventory ledger projections
python manage.py reconcile_inventory
# Run the application checks and all tests on SQLite
python manage.py check
python manage.py makemigrations --check --dry-run
python -m pytest
# Quality checks
python -m ruff check .
python -m ruff format --check .
python -m pip check
python -m compileall -q apps config manage.py
python manage.py collectstatic --noinputSQLite cannot prove row-lock behavior. Run integrity and concurrency tests on PostgreSQL before release:
$env:TEST_DATABASE_URL = "postgresql://retail_pos_test:password@127.0.0.1:5432/retail_pos_test"
python -m pytest
Remove-Item Env:TEST_DATABASE_URLInstall PostgreSQL locally or use a managed PostgreSQL service. From psql,
create separate application and test databases with a dedicated owner:
CREATE ROLE retail_pos LOGIN PASSWORD 'replace-with-a-strong-password';
CREATE DATABASE retail_pos OWNER retail_pos;
CREATE DATABASE retail_pos_test OWNER retail_pos;For a production-style PowerShell session:
$env:DJANGO_SETTINGS_MODULE = "config.settings.production"
$env:SECRET_KEY = "replace-with-at-least-50-random-characters"
$env:DEBUG = "False"
$env:ALLOWED_HOSTS = "pos.example.com"
$env:CSRF_TRUSTED_ORIGINS = "https://pos.example.com"
$env:DATABASE_URL = "postgresql://retail_pos:password@db.example.com:5432/retail_pos?sslmode=require"
$env:TIME_ZONE = "Africa/Casablanca"
$env:MEDIA_ROOT = "D:\RetailPOS\media"
$env:PRIVATE_MEDIA_ROOT = "D:\RetailPOS\private_media"
$env:STATIC_ROOT = "D:\RetailPOS\staticfiles"
python manage.py migrate --noinput
python manage.py bootstrap_roles
python manage.py collectstatic --noinput
python manage.py check --deployconfig.settings.production rejects DEBUG=True, weak/missing secret keys,
wildcard/missing hosts, non-HTTPS CSRF origins, and missing PostgreSQL
configuration.
The project deliberately does not auto-load .env. Supply variables through
the process manager, operating-system environment, container orchestration, or
a secret manager. .env.example documents the supported baseline.
The application is a modular Django monolith:
| App | Responsibility |
|---|---|
accounts |
Employees, identity, locations, roles, permissions |
core |
Businesses, settings, locations, sequences, idempotency |
audit |
Append-only security and business audit events |
products |
Categories, units, product master data and images |
inventory |
Balances, immutable stock movements, costing |
registers |
Drawers, sessions, cash movement and reconciliation |
sales |
POS checkout, snapshots, payments, receipts, returns |
customers |
Customer master data and account ledger |
suppliers |
Supplier master data |
purchases |
Orders, receipts, invoices, supplier payments |
expenses |
Posted expenses and private attachments |
reports |
Dashboard selectors, reports, charts, CSV exports |
HTTP views coordinate requests. Forms and command dataclasses validate input. Transactional services own state changes and locking. Selectors own optimized, business-scoped reads. Model validation and database constraints provide a second line of defense.
- The browser is never trusted for totals, prices, cost, tax, permissions, or business/location ownership.
- Money and sellable quantities use
Decimal, never binary floating point. - Sales, returns, purchases, stock adjustments, payments, expenses, and register changes are atomic and auditable.
- Completed financial records are not edited or deleted; cancellation, return, refund, void, and correction records preserve history.
- Inventory changes only through the stock ledger. Row locks prevent overselling on PostgreSQL unless negative stock is explicitly enabled.
- Checkout and other irreversible browser commands use idempotency keys.
- Historical margin uses the product cost snapshot stored on each sale item.
- Return quantities are capped against net unreturned sold quantities under a database lock.
- Returns from on-account sales cannot pay out uncollected value; they must credit the customer account.
- Expense attachments are stored outside public media and served only through an authenticated, scoped view.
- Closed register snapshots are immutable. Later cash corrections restore the accounting workflow and are explicitly flagged for drawer reconciliation instead of rewriting a closed session.
- A normal business Admin is not a global Django support superuser.
Before releasing:
- Use PostgreSQL, a dedicated least-privilege database role, TLS in transit, and tested automated backups with point-in-time recovery where available.
- Generate independent strong values for
SECRET_KEY,LOGIN_THROTTLE_HMAC_KEY, database credentials, and infrastructure secrets. - Set exact
ALLOWED_HOSTS, HTTPSCSRF_TRUSTED_ORIGINS, proxy trust, cookie, HSTS, and canonical-host behavior for the real topology. - Terminate HTTPS at a trusted reverse proxy and run the WSGI/ASGI application
with a production server; do not expose
runserver. - Store static files through the reverse proxy/CDN. Keep public product media separate from private expense receipts, restrict filesystem permissions, and include both in the backup policy as appropriate.
- Run migrations as a controlled release step, then
bootstrap_roles,collectstatic,check --deploy, the full PostgreSQL suite, and Ruff. - Change/remove all demo credentials and data.
- Configure structured log collection, alerts, uptime monitoring, error tracking, database monitoring, clock synchronization, and disk-capacity alerts without logging secrets or private attachments.
- Test restore, rollback, receipt printing, barcode input, role access, and register close on production-like hardware.
- Review tax, receipt-numbering, record-retention, customer-credit, and refund policies for the deployment jurisdiction.
Confirm DJANGO_SETTINGS_MODULE. Production settings intentionally fail if the
secret key, hosts, HTTPS origins, or PostgreSQL variables are missing.
Run python manage.py migrate, then python manage.py bootstrap_roles using
the same settings and database as the server.
Run python manage.py bootstrap_roles, sign out and back in, and verify the
employee has the intended role and location access. Hiding a link is only a UI
convenience; the server still enforces every permission.
Open a register session for the cashier at the same location. Only one active session per cashier is allowed by default.
SQLite is intended only for initial local use and cannot model the required concurrent row locks. Use PostgreSQL for realistic multi-user operation and concurrency testing.
Run python manage.py collectstatic --noinput, confirm the reverse proxy serves
STATIC_ROOT, and ensure the configured Content Security Policy permits the
pinned Bootstrap/Chart.js assets.
Product images use public media. Expense receipts intentionally do not: users
must download them through the protected expense endpoint. Check permissions
and the distinct MEDIA_ROOT and PRIVATE_MEDIA_ROOT paths.
Never commit .env, SQLite databases, uploaded media, private receipts,
collected static files, logs, credentials, virtual environments, caches, or
generated reports. The retired ProofReply project remains recoverable from Git
history at commit e514dd2; its working-tree deletion is intentional.