The Project Costs feature allows you to track expenses beyond hourly work on projects. This includes costs like travel, materials, third-party services, equipment rentals, software licenses, and other project-related expenses.
- Add Costs: Add project costs with description, category, amount, and date
- Edit Costs: Modify cost details (admins and cost creators only)
- Delete Costs: Remove costs that haven't been invoiced yet
- Categories: Organize costs by category. Costs use the same list as expenses: Admin → Expense Categories. The forms offer the active categories; a cost keeps its category after that category is deactivated
- Billable Status: Mark costs as billable or non-billable to clients
- Multiple Currencies: Support for EUR, USD, GBP, CHF
- Cost Summary: View total costs, billable costs, and total project value
- Recent Costs: See the 5 most recent costs in the project overview
- Statistics: Updated project statistics include cost information
- Quick Actions: Add, edit, and delete costs directly from the project page
- Automatic Inclusion: Include project costs when generating invoices
- Cost Tracking: Track which costs have been invoiced
- Uninvoiced Costs: View all uninvoiced billable costs for a project
- Invoice Items: Costs appear as separate line items on invoices
- Project Reports: Reports now include project costs in calculations
- Cost Breakdown: View costs by category
- Total Project Value: Combination of billable hours and billable costs
- Date Filtering: Filter costs by date range
The project_costs table includes:
- id: Primary key
- project_id: Foreign key to projects table
- user_id: Foreign key to users table (who added the cost)
- description: Brief description of the cost
- category_id: Foreign key to expense_categories table (nullable, set to NULL if the category is deleted)
- category: Legacy category string, kept for one release and filled on every write (lowercased category name). Reads use
category_idand fall back to this string - amount: Cost amount (Decimal)
- currency_code: Currency code (default: EUR)
- billable: Whether the cost is billable to client
- invoiced: Whether the cost has been invoiced
- invoice_id: Reference to invoice (if invoiced)
- cost_date: Date of the cost
- notes: Additional notes
- receipt_path: Path to uploaded receipt (future enhancement)
- created_at: Timestamp when cost was created
- updated_at: Timestamp when cost was last updated
Project costs and recurring project costs take their category from Expense Categories, the list expenses use. An admin manages it under Admin → Expense Categories.
- The add, edit and recurring cost forms offer the active categories.
- A deactivated category disappears from the forms for new costs. An existing cost keeps it, and its edit form shows it as "(inactive)".
- The category filter on the costs page and the breakdown by category use the same list.
Before this change, costs had a fixed list (travel, materials, services, equipment, software, other). Migration 218_project_cost_expense_categories links every category string in use, plus that fixed list, to an expense category by code or name (case-insensitive). A missing category is created with receipts and approval off.
The API (/api/v1/projects/<id>/costs, /api/v1/project-costs/<id>, recurring costs) accepts category_id or category (a code or name). A string that matches no category is stored as before, with category_id empty. Responses return category (the stored string, as before), category_id and category_name (the category's display name).
- Navigate to a project page
- Scroll to the "Project Costs & Expenses" section
- Click "Add Cost"
- Fill in:
- Description (required)
- Category (required, from Expense Categories)
- Amount (required)
- Date (required)
- Currency (default: EUR)
- Notes (optional)
- Billable checkbox (default: checked)
- Click "Add Cost"
- Project Page: Shows the 5 most recent costs
- Statistics Card: Shows total costs and total project value
- Full List: Click "View All Costs" to see all costs for a project
Preferred — new invoice step 1:
- Invoices → New invoice (or a draft's step 1)
- Choose client, period, and projects — period project costs appear under Hours (ticked by default)
- Choose Show costs as (per cost / by category / one line)
- Create draft — costs are billed with the hours; the draft has a Project costs block (Regroup costs, Log a cost, recurring monthly)
Alternate — Generate from Time/Costs on a draft still lists uninvoiced costs. Invoiced costs are linked so they are not billed twice; cancel/reissue releases them.
The project view now shows:
- Total Hours: All tracked hours
- Billable Hours: Hours marked as billable
- Total Costs: Sum of all project costs
- Budget Used (Hours): Budget consumed by hourly work
- Total Project Value: Billable hours cost + billable costs
GET /projects/<id>/costs- List all costs for a projectGET /projects/<id>/costs/add- Show add cost formPOST /projects/<id>/costs/add- Create a new costGET /projects/<id>/costs/<cost_id>/edit- Show edit cost formPOST /projects/<id>/costs/<cost_id>/edit- Update a costPOST /projects/<id>/costs/<cost_id>/delete- Delete a costGET /api/projects/<id>/costs- Get costs as JSON
project.total_costs- Total of all costsproject.total_billable_costs- Total of billable costsproject.total_project_value- Billable hours + billable costs
The Project Costs feature is implemented via Alembic migration 018.
# Apply all pending migrations including 018
flask db upgrade
# Check current migration status
flask db current
# View migration history
flask db history- Migration ID: 018
- File:
migrations/versions/018_add_project_costs_table.py - Creates:
project_coststable with indexes and foreign keys - Depends on: Migration 017 (reporting and invoicing extensions)
- Idempotent: Can be safely run multiple times
- Database-aware: Handles SQLite, PostgreSQL, and MySQL differences
- Safe FK handling: Only creates invoice FK if invoices table exists
- Verbose logging: Prints progress during migration
- Error handling: Clear error messages if migration fails
A test script is provided to validate migration 018:
python test_migration_018.pyThis checks:
- Migration file structure and syntax
- Required columns and indexes
- Foreign key definitions
- Model import compatibility
- Migration chain integrity
No new environment variables are required. The feature uses existing database connection settings.
- All Users: Can add costs to projects they work on
- Cost Creators: Can edit and delete their own costs (if not invoiced)
- Admins: Can edit and delete any costs (if not invoiced)
- Invoiced Costs: Cannot be deleted to maintain invoice integrity
Potential future improvements:
- Receipt Uploads: Upload and store receipt images
- Cost Approval Workflow: Require approval for costs above threshold
- Cost Budgets: Set and track budgets specifically for costs
- Cost Analytics: Advanced analytics and visualizations for costs
- Recurring Costs: Support for recurring project costs
- Multi-currency Conversion: Automatic currency conversion
- Export Costs: Export costs to CSV/PDF
- Cost Templates: Create templates for common costs
The UI maintains the TimeTracker application's light and clean design:
- Clean cards with subtle shadows
- Light color scheme with primary blue accents
- Clear typography and spacing
- Responsive design for mobile devices
- Intuitive icons and badges
- Smooth animations and transitions
ProjectCostmodel inapp/models/project_cost.py- Relationships with
Project,User, andInvoicemodels - Cascade deletion when parent project or user is deleted
- Cost management routes in
app/routes/projects.py - Invoice generation updated in
app/routes/invoices.py - Report calculations updated in
app/routes/reports.py
templates/projects/add_cost.html- Add cost formtemplates/projects/edit_cost.html- Edit cost formtemplates/projects/view.html- Updated with costs section
For issues or questions about the Project Costs feature:
- Check the TimeTracker documentation
- Review the code in the models and routes files
- Check the migration scripts for database setup
- Contact your system administrator
Comprehensive tests are provided in tests/test_project_costs.py:
- ProjectCost creation and validation
- Relationship testing (Project, User, Invoice)
- Timestamp and constraint validation
- Method testing (to_dict, mark_as_invoiced, etc.)
get_project_costs()with filtersget_total_costs()calculationsget_uninvoiced_costs()filteringget_costs_by_category()grouping- Date range filtering
- Billable/non-billable filtering
- Cascade deletion with projects
- Invoice marking workflow
- Foreign key constraints
- Basic CRUD operations
- Relationship loading
- Query execution
Run the tests:
# Run all project cost tests
pytest tests/test_project_costs.py -v
# Run specific test class
pytest tests/test_project_costs.py::TestProjectCostModel -v
# Run with coverage
pytest tests/test_project_costs.py --cov=app.models.project_cost --cov-report=htmlIf migration 018 fails:
-
Check database connection:
flask db current
-
View detailed migration logs: The migration prints verbose output showing each step.
-
Common issues:
- Index already exists: Migration is idempotent and checks before creating
- Foreign key errors: Ensure projects and users tables exist
- Boolean defaults: Migration handles different database dialects
-
Manual rollback (if needed):
flask db downgrade 017
-
Re-run migration:
flask db upgrade 018
The migration includes:
- NOT NULL constraints on required fields
- Foreign key constraints with CASCADE deletion
- Indexes on frequently queried columns
- Server-side defaults for timestamps and boolean fields
-
v1.1 (2025-01-15): Migration improvements
- Fixed index column bug in migration 018
- Added comprehensive test suite (70+ tests)
- Improved migration error handling and logging
- Enhanced documentation with troubleshooting guide
-
v1.0 (2024-01-01): Initial release
- Basic cost tracking
- Invoice integration
- Report integration
- CRUD operations