Add ability for admins to edit or delete unpaid payroll adjustments directly from the payroll dashboard. Clickable adjustment badges open edit/delete modals with type-specific handling (LOAN cascades, OVERTIME un-pricing). No model changes or migrations needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4.0 KiB
4.0 KiB
Fox Fitt LabourPay
Project Overview
Django payroll management system for Fox Fitt Construction, a civil works contractor specializing in solar farm foundation installations. Manages field worker attendance, payroll processing, employee loans, and business expenses for solar farm projects.
Tech Stack
- Django 5.x, Python 3.11, MariaDB
- Bootstrap 5 with Material Design-inspired styling, vanilla JavaScript
- PDF generation for payslips and receipts
- SMTP email integration for automated document delivery
- Apache reverse proxy with systemd service management
Project Structure
config/— Django project settings, URLs, WSGI/ASGI entrypointscore/— Single main app containing ALL business logic, models, views, forms, templates, and migrationsai/— Local AI API integration modulemedia/workers/ids/— Worker ID photo uploadsstatic/— Source static files (custom CSS)staticfiles/— Collected static assets (Bootstrap, Popper.js, admin)
Key Business Rules
- All business logic lives in the
core/app — do not create additional apps - Workers have a
day_ratecalculated automatically from monthly salary / 20 working days - PIN authentication (4-digit) exists alongside password auth for quick field access
- Supervisors can only see their assigned projects and teams
- Admins have full access to payroll, adjustments, and resource management
- WorkLog is the central attendance record — links workers to projects on specific dates
- Attendance logging includes conflict detection to prevent double-logging
- Loans have automated repayment deductions during payroll processing
- Cascading deletes use SET_NULL for supervisors to preserve historical data
Key Models
- UserProfile — extends User with PIN and is_admin flag
- Project — work sites/contracts with supervisor assignments
- Worker — profiles with salary, day_rate, employment details
- Team — groups of workers under a supervisor
- WorkLog — daily attendance records (worker + project + date)
- PayrollRecord — completed payments linked to WorkLog entries
- PayrollAdjustment — bonuses, deductions, overtime, loan repayments
- Loan — worker advances with balance tracking
- ExpenseReceipt / ExpenseLineItem — business expense records
Commands
python manage.py runserver 0.0.0.0:8000— run dev serverpython manage.py migrate— apply database migrationspython manage.py collectstatic— collect static files for productionpython manage.py setup_groups— configure permission groupspython manage.py update_permission_names— update permission display namespython manage.py check— system check (ignore staticfiles warnings about missingassets/andnode_modules/dirs — pre-existing, harmless)
Development Workflow
- Active development branch:
ai-dev(PR target:master) - Admin check in views:
is_admin(request.user)helper (imported at top of views.py) - "Unpaid" adjustment =
payroll_record__isnull=True(no linked PayrollRecord) - POST-only mutation views pattern: check
request.method != 'POST'→ redirect, then process - Template UI pattern: Bootstrap 5 modals with dynamic JS wiring, data-* attributes on clickable elements
PayrollAdjustment Type Handling
- BONUS / DEDUCTION — standalone, no linked objects
- LOAN — links to
Loanmodel viaadj.loanFK; editing syncs loan amount/balance/reason; deleting cascades to Loan + unpaid repayments (blocked if paid repayments exist) - OVERTIME — links to
WorkLogviaadj.work_logFK; deleting removes worker fromwork_log.overtime_paid_toM2M (un-prices the OT) - LOAN_REPAYMENT — links to
Loanviaadj.loanFK; loan balance only changes during payment processing
Important Context
- Read APP_DOCUMENTATION.md for detailed workflows (attendance, payroll, expenses)
- Environment variables loaded from
../.env - The owner (Konrad) is not a developer — explain changes clearly and avoid unnecessary complexity
- This system handles real payroll for 14 field workers — accuracy is critical