diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..b5f51e6c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,120 @@ +# Changelog + +All notable changes to TimeTracker will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added +- Additional features and improvements in development + +## [4.6.0] - 2025-12-14 + +### Added +- **Comprehensive Issue/Bug Tracking System** - Complete issue and bug tracking functionality with full lifecycle management + +## [4.5.1] - 2025-12-13 + +### Changed +- **Performance Optimization** - Optimized task listing queries and improved version management +- **Version Management** - Enhanced version management system + +## [4.5.0] - 2025-12-12 + +### Added +- **Advanced Report Builder** - Iterative report generation with email distribution capabilities +- **Quick Task Creation** - Create tasks directly from the Start Timer modal for faster workflow +- **Kanban Board Enhancements** - Added user filter and flexible column layout options +- **PWA Install UI** - Improved Progressive Web App installation user interface + +### Fixed +- **Permission and Role Management** - Fixed bugs in permission and role management system + +### Changed +- **Error Handling** - Improved error handling throughout the application +- **Performance Logging** - Enhanced performance logging and monitoring + +## [4.4.1] - 2025-12-08 + +### Added +- **Custom Reports Enhancement** - Enhanced custom reports and scheduled reports functionality + +### Fixed +- **Dashboard Cache Invalidation** - Fixed dashboard cache invalidation when editing timer entries (#342) +- **Custom Field Definitions** - Fixed graceful handling of missing custom_field_definitions table (#344) + +## [4.4.0] - 2025-12-03 + +### Added +- **Project Custom Fields** - Add custom fields to projects for enhanced project tracking +- **File Attachments** - File attachment support for projects and clients +- **Salesman-Based Report Splitting** - Report splitting and email distribution based on salesperson assignments + +### Changed +- **Performance Optimization** - Optimized task queries and fixed N+1 performance issues +- **Version Update** - Updated setup.py version to 4.4.0 + +## [4.3.2] - 2025-12-02 + +### Added +- **Custom Field Filtering** - Custom field filtering and display for clients, projects, and time entries +- **Client Count Tracking** - Client count tracking and cleanup for custom field definitions +- **Unpaid Hours Report** - New unpaid hours report with Ajax filtering and Excel export +- **Time Entries Overview** - New time entries overview page with AJAX filters and bulk mark as paid +- **Configurable Duplicate Detection** - Configurable duplicate detection fields for CSV client import +- **Enhanced Audit Logging** - Improved error handling and diagnostic tools for audit logging + +### Changed +- **Offline Sync** - Enhanced offline sync functionality and performance improvements +- **Error Handling** - Improved error handling throughout the application +- **Docker Healthchecks** - Enhanced Docker healthcheck functionality + +## [4.3.1] - 2025-12-01 + +### Changed +- **Offline Sync** - Enhanced offline sync functionality and performance improvements + +## [4.3.0] - 2025-12-01 + +### Added +- **Custom Field Filtering** - Custom field filtering and display for clients, projects, and time entries +- **Client Count Tracking** - Client count tracking and cleanup for custom field definitions +- **Unpaid Hours Report** - New unpaid hours report with Ajax filtering and Excel export +- **Time Entries Overview** - New time entries overview page with AJAX filters and bulk mark as paid +- **Configurable Duplicate Detection** - Configurable duplicate detection fields for CSV client import +- **Enhanced Audit Logging** - Improved error handling and diagnostic tools for audit logging + +### Changed +- **Error Handling** - Improved error handling throughout the application +- **Docker Healthchecks** - Enhanced Docker healthcheck functionality +- **Offline Sync** - Enhanced offline sync functionality + +## [4.2.1] - 2025-12-01 + +### Fixed +- **AUTH_METHOD=none** - Fixed authentication method when set to none +- **Schema Verification** - Added comprehensive schema verification + +## [4.2.0] - 2025-11-30 + +### Added +- **CSV Import/Export** - CSV import/export for clients with custom fields and contacts +- **Global Custom Field Definitions** - Global custom field definitions with link template support +- **Paid Status Tracking** - Paid status tracking for time entries with invoice reference +- **OAuth Credentials Dropdown** - Converted OAuth credentials section to dropdown in System Settings + +--- + +## Release Notes Format + +Each release includes: +- **Added** - New features +- **Changed** - Changes in existing functionality +- **Deprecated** - Soon-to-be removed features +- **Removed** - Removed features +- **Fixed** - Bug fixes +- **Security** - Security improvements + +For detailed information about each release, see the [GitHub Releases](https://github.com/drytrix/TimeTracker/releases) page. diff --git a/IMPLEMENTATION_COMPLETE.md b/IMPLEMENTATION_COMPLETE.md deleted file mode 100644 index 83e416eb..00000000 --- a/IMPLEMENTATION_COMPLETE.md +++ /dev/null @@ -1,149 +0,0 @@ -# โ Feature Implementation Complete - -**Date:** 2025-01-27 -**Total Features:** 24 -**Completed:** 17 (71%) -**Status:** ๐ **MAJOR MILESTONE ACHIEVED** - ---- - -## โ COMPLETED FEATURES (17/24) - -### ๐ฏ Core Infrastructure (3) -1. โ **Offline Mode with Sync** - Complete IndexedDB implementation -2. โ **Automation Workflow Engine** - Full rule-based automation -3. โ **Activity Feed UI** - Real-time activity feed - -### ๐ Integrations (4) -4. โ **Google Calendar** - Two-way sync -5. โ **Asana** - Project/task sync -6. โ **Trello** - Board/card sync -7. โ **QuickBooks** - Invoice/expense sync - -### ๐ Workflows & Approvals (3) -8. โ **Time Approval Workflow** - Manager approval system -9. โ **Client Approval Workflow** - Client-side approvals -10. โ **Recurring Tasks** - Automated task creation - -### ๐ฌ Team Collaboration (2) -11. โ **Team Chat** - Real-time messaging system -12. โ **@Mentions UI** - Autocomplete mentions component - -### ๐จ Customization (1) -13. โ **Client Portal Customization** - Branding & theme options - -### ๐ Reporting (3) -14. โ **PowerPoint Export** - Presentation generation -15. โ **Currency Auto-Conversion** - Real-time rate fetching -16. โ **Currency Historical Rates** - Rate history tracking - -### ๐ Automation (1) -17. โ **Recurring Tasks** - Task templates with auto-creation - ---- - -## ๐ REMAINING FEATURES (7/24) - -### High Priority (1) -1. โณ **Custom Report Builder** - Drag-and-drop UI component - -### Medium/Low Priority (6) -2. โณ **Pomodoro Enhancements** - Better timer integration -3. โณ **Expense OCR Enhancement** - Improve receipt scanning -4. โณ **Expense GPS Tracking** - Mileage tracking with GPS -5. โณ **AI Suggestions** - Smart time entry suggestions -6. โณ **AI Categorization** - Automatic categorization -7. โณ **Gamification** - Badges and leaderboards - ---- - -## ๐ Implementation Summary - -### Files Created (35+) -- **Models:** 8 files (workflows, approvals, chat, customization, recurring tasks) -- **Services:** 6 files (workflow engine, approval services, currency service) -- **Routes:** 8 files (workflows, approvals, chat, customization, activity feed) -- **Integrations:** 4 files (Google Calendar, Asana, Trello, QuickBooks) -- **Frontend:** 3 files (offline sync, activity feed, mentions) -- **Utilities:** 2 files (PowerPoint export, currency service) -- **Migrations:** 4 files -- **Documentation:** 4 files - -### Database Tables Added -1. `workflow_rules` & `workflow_executions` -2. `time_entry_approvals` & `approval_policies` -3. `recurring_tasks` -4. `client_portal_customizations` -5. `chat_channels`, `chat_messages`, `chat_channel_members`, `chat_read_receipts` -6. `client_time_approvals` & `client_approval_policies` - ---- - -## ๐ Next Steps - -### Immediate Actions - -1. **Run Migrations:** - ```bash - flask db upgrade - ``` - -2. **Add Dependencies:** - ```txt - python-pptx==0.6.23 - ``` - -3. **Register Routes:** - Add to `app/__init__.py`: - ```python - from app.routes.workflows import workflows_bp - from app.routes.time_approvals import time_approvals_bp - from app.routes.activity_feed import activity_feed_bp - from app.routes.recurring_tasks import recurring_tasks_bp - from app.routes.team_chat import team_chat_bp - from app.routes.client_portal_customization import client_portal_customization_bp - - app.register_blueprint(workflows_bp) - app.register_blueprint(time_approvals_bp) - app.register_blueprint(activity_feed_bp) - app.register_blueprint(recurring_tasks_bp) - app.register_blueprint(team_chat_bp) - app.register_blueprint(client_portal_customization_bp) - ``` - -4. **Add Scripts to Templates:** - - `offline-sync.js` - Base template - - `activity-feed.js` - Dashboard - - `mentions.js` - Chat/comments - -5. **Update Models:** - - Already updated in `app/models/__init__.py` - ---- - -## ๐ Statistics - -- **Completion Rate:** 71% (17/24) -- **Lines of Code:** ~8,000+ -- **New Services:** 6 -- **New Integrations:** 4 -- **Database Tables:** 13 new tables -- **API Endpoints:** 70+ new endpoints -- **JavaScript Components:** 3 major components - ---- - -## ๐ฏ Key Achievements - -โ **Complete Integration Framework** - OAuth-ready connectors -โ **Full Workflow Automation** - Rule-based system -โ **Team Collaboration** - Chat with mentions -โ **Approval Systems** - Manager & client approvals -โ **Portal Customization** - Full branding support -โ **Export Enhancements** - PowerPoint support -โ **Currency Features** - Auto-conversion & history - ---- - -**Status:** โ **71% COMPLETE** -**Next Focus:** Custom Report Builder UI diff --git a/IMPLEMENTATION_SUMMARY.md b/IMPLEMENTATION_SUMMARY.md deleted file mode 100644 index 41ad5ebc..00000000 --- a/IMPLEMENTATION_SUMMARY.md +++ /dev/null @@ -1,167 +0,0 @@ -# Feature Implementation Summary - -**Date:** 2025-01-27 -**Status:** Foundation Complete, Ready for Continued Development - -## โ Completed Implementations - -### 1. Offline Mode with Sync โ -**Status:** Complete -**Files:** -- `app/static/offline-sync.js` - Full offline sync manager - -**Features Implemented:** -- โ IndexedDB storage for time entries, tasks, projects -- โ Sync queue management -- โ Automatic sync when connection restored -- โ Conflict resolution framework -- โ UI indicators for offline status -- โ Background sync via Service Worker -- โ Pending sync count tracking - -**Integration Required:** -- Add `` to base template -- Add offline indicator UI element -- Integrate `offlineSyncManager.createTimeEntryOffline()` into time entry forms - -### 2. Automation Workflow Engine โ -**Status:** Complete (Backend) -**Files:** -- `app/models/workflow.py` - WorkflowRule and WorkflowExecution models -- `app/services/workflow_engine.py` - Complete workflow engine -- `app/routes/workflows.py` - Full CRUD API routes -- `migrations/versions/069_add_workflow_automation.py` - Database migration - -**Features Implemented:** -- โ Rule-based automation system -- โ 8 trigger types (task status, time logged, deadlines, etc.) -- โ 8 action types (log time, notifications, status updates, etc.) -- โ Template variable resolution ({{task.name}}) -- โ Execution logging and history -- โ Priority-based rule execution -- โ REST API endpoints - -**Next Steps:** -1. Run migration: `flask db upgrade` -2. Register workflow routes in `app/__init__.py` -3. Create UI templates for workflow builder -4. Integrate workflow triggers into existing code: - - Call `WorkflowEngine.trigger_event()` when tasks change status - - Call `WorkflowEngine.trigger_event()` when time entries are created - - Add triggers for deadlines and budget thresholds - -**Integration Points:** -```python -# In task status change handler: -from app.services.workflow_engine import WorkflowEngine - -WorkflowEngine.trigger_event('task_status_change', { - 'data': { - 'task_id': task.id, - 'old_status': old_status, - 'new_status': task.status, - 'task': task.to_dict(), - 'user_id': current_user.id - } -}) -``` - -### 3. Google Calendar Integration โ -**Status:** Complete -**Files:** -- `app/integrations/google_calendar.py` - Full Google Calendar connector -- Updated `app/integrations/registry.py` - Registered connector - -**Features Implemented:** -- โ OAuth 2.0 authentication -- โ Two-way calendar sync -- โ Time entry to calendar event conversion -- โ Calendar event updates -- โ Multiple calendar support -- โ Configurable sync direction - -**Next Steps:** -1. Configure Google OAuth credentials in settings -2. Update calendar routes to use new connector -3. Add sync scheduling (background jobs) -4. Test OAuth flow - -**Configuration Required:** -```env -GOOGLE_CLIENT_ID=your_client_id -GOOGLE_CLIENT_SECRET=your_client_secret -``` - -## ๐ Remaining Features (Prioritized) - -### High Priority -1. **Asana Integration** - Similar to Google Calendar connector -2. **Trello Integration** - Similar pattern -3. **QuickBooks Integration** - More complex, requires QuickBooks API -4. **Time Approval Workflow** - Manager approval system -5. **Client Approval Workflow** - Client-side approval - -### Medium Priority -6. **Custom Report Builder** - Drag-and-drop UI component -7. **PowerPoint Export** - Use python-pptx library -8. **Team Chat** - Real-time messaging system -9. **Activity Feed UI** - Display Activity model data -10. **@Mentions UI** - Enhance existing comments - -### Lower Priority -11. **AI Features** - Requires ML/AI service integration -12. **Gamification** - Badges and leaderboards -13. **Expense OCR Enhancement** - Improve pytesseract usage -14. **GPS Tracking** - Browser geolocation API -15. **Recurring Tasks** - Similar to recurring invoices -16. **Currency Auto-Conversion** - Exchange rate API integration - -## ๐ Quick Start Guide - -### 1. Run Migrations -```bash -flask db upgrade -``` - -### 2. Register Workflow Routes -Add to `app/__init__.py`: -```python -from app.routes.workflows import workflows_bp -app.register_blueprint(workflows_bp) -``` - -### 3. Add Offline Sync to Templates -Add to `app/templates/base.html`: -```html - -
-``` - -### 4. Integrate Workflow Triggers -Add workflow triggers to key events: -- Task status changes -- Time entry creation -- Invoice creation/payment -- Budget threshold reached - -## ๐ Notes - -- All implementations follow existing codebase patterns -- Database migrations are ready to run -- Integration framework is extensible -- Service layer pattern is maintained -- Error handling and logging included - -## ๐ Next Session Priorities - -1. Complete UI templates for workflows -2. Integrate workflow triggers -3. Add Asana/Trello integrations -4. Implement time approval workflow -5. Create custom report builder - ---- - -**Total Features Implemented:** 3/24 -**Foundation Complete:** โ -**Ready for UI Development:** โ diff --git a/README.md b/README.md index ce3043c9..455310f6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **Track time. Manage projects. Generate invoices. All in one place.** -[๐ What's New](#-whats-new) โข [๐ Quick Start](#-quick-start) โข [โจ Features](#-features) โข [๐ธ Screenshots](#-screenshots) โข [๐ Getting Started](docs/GETTING_STARTED.md) โข [๐ Documentation](docs/) โข [๐ณ Deploy](#-deployment) +[๐ What's New](#-whats-new) โข [๐ Quick Start](#-quick-start) โข [โจ Features](#-features) โข [๐ธ Screenshots](#-screenshots) โข [๐ Getting Started](docs/GETTING_STARTED.md) โข [๐ Documentation](docs/) โข [๐ Changelog](CHANGELOG.md) โข [๐ณ Deploy](#-deployment) --- @@ -28,6 +28,17 @@ TimeTracker is a **self-hosted, web-based time tracking application** designed f TimeTracker has been continuously enhanced with powerful new features! Here's what's been added recently: +> **๐ For complete release history, see [CHANGELOG.md](CHANGELOG.md)** + +**Latest Release: v4.6.0** (December 2025) +- โจ **Comprehensive Issue/Bug Tracking System** โ Complete issue and bug tracking functionality with full lifecycle management + +**Recent Releases:** +- **v4.5.1** โ Performance optimizations and version management improvements +- **v4.5.0** โ Advanced Report Builder, quick task creation, Kanban enhancements, and PWA improvements +- **v4.4.1** โ Dashboard cache fixes and custom reports enhancements +- **v4.4.0** โ Project custom fields, file attachments, and salesman-based report splitting + ### ๐ฏ **Major Feature Additions** #### ๐งพ **Complete Invoicing System** @@ -336,7 +347,7 @@ docker-compose up -d **First login creates the admin account** โ just enter your username! -**๐ See the complete setup guide:** [`docs/DOCKER_COMPOSE_SETUP.md`](docs/DOCKER_COMPOSE_SETUP.md) +**๐ See the complete setup guide:** [`docs/admin/configuration/DOCKER_COMPOSE_SETUP.md`](docs/admin/configuration/DOCKER_COMPOSE_SETUP.md) ### Option 2: Docker with Plain HTTP (Development/Testing) @@ -405,15 +416,18 @@ Even if you're not billing anyone, understanding where your time goes is valuabl Comprehensive documentation is available in the [`docs/`](docs/) directory: +### Release Information +- **[๐ Changelog](CHANGELOG.md)** โ Complete release history with all changes and new features (โญ See what's new!) + ### Getting Started - **[๐ Getting Started Guide](docs/GETTING_STARTED.md)** โ Complete beginner's guide (โญ Start here!) -- **[Installation Guide](docs/DOCKER_PUBLIC_SETUP.md)** โ Detailed setup instructions +- **[Installation Guide](docs/admin/configuration/DOCKER_PUBLIC_SETUP.md)** โ Detailed setup instructions - **[Requirements](docs/REQUIREMENTS.md)** โ System requirements and dependencies -- **[Troubleshooting](docs/DOCKER_STARTUP_TROUBLESHOOTING.md)** โ Common issues and solutions -- **[CSRF Token Issues](CSRF_TROUBLESHOOTING.md)** โ Fix "CSRF token missing or invalid" errors -- **[CSRF IP Access Fix](CSRF_IP_ACCESS_FIX.md)** โ ๐ฅ Fix cookies not working when accessing via IP address -- **[HTTPS Auto-Setup](README_HTTPS_AUTO.md)** โ ๐ Automatic HTTPS at startup (one command!) -- **[HTTPS Manual Setup (mkcert)](README_HTTPS.md)** โ ๐ Manual HTTPS with no certificate warnings +- **[Troubleshooting](docs/admin/configuration/DOCKER_STARTUP_TROUBLESHOOTING.md)** โ Common issues and solutions +- **[CSRF Token Issues](docs/admin/security/CSRF_TROUBLESHOOTING.md)** โ Fix "CSRF token missing or invalid" errors +- **[CSRF IP Access Fix](docs/admin/security/CSRF_IP_ACCESS_FIX.md)** โ ๐ฅ Fix cookies not working when accessing via IP address +- **[HTTPS Auto-Setup](docs/admin/security/README_HTTPS_AUTO.md)** โ ๐ Automatic HTTPS at startup (one command!) +- **[HTTPS Manual Setup (mkcert)](docs/admin/security/README_HTTPS.md)** โ ๐ Manual HTTPS with no certificate warnings ### Features - **[๐ Complete Features Overview](docs/FEATURES_COMPLETE.md)** โ Comprehensive documentation of all 120+ features (โญ Complete reference!) @@ -430,15 +444,15 @@ Comprehensive documentation is available in the [`docs/`](docs/) directory: - **[Role-Based Permissions](docs/ADVANCED_PERMISSIONS.md)** โ Granular access control ### Technical Documentation -- **[Project Structure](docs/PROJECT_STRUCTURE.md)** โ Codebase architecture +- **[Project Structure](docs/development/PROJECT_STRUCTURE.md)** โ Codebase architecture - **[Database Migrations](migrations/README.md)** โ Database schema management -- **[Version Management](docs/VERSION_MANAGEMENT.md)** โ Release and versioning -- **[CSRF Configuration](docs/CSRF_CONFIGURATION.md)** โ Security and CSRF token setup for Docker +- **[Version Management](docs/admin/deployment/VERSION_MANAGEMENT.md)** โ Release and versioning +- **[CSRF Configuration](docs/admin/security/CSRF_CONFIGURATION.md)** โ Security and CSRF token setup for Docker - **[CI/CD Documentation](docs/cicd/)** โ Continuous integration setup ### Contributing -- **[Contributing Guidelines](docs/CONTRIBUTING.md)** โ How to contribute -- **[Code of Conduct](docs/CODE_OF_CONDUCT.md)** โ Community standards +- **[Contributing Guidelines](docs/development/CONTRIBUTING.md)** โ How to contribute +- **[Code of Conduct](docs/development/CODE_OF_CONDUCT.md)** โ Community standards --- @@ -478,7 +492,7 @@ docker-compose up -d docker-compose -f docker-compose.remote.yml up -d ``` -> **โ ๏ธ Security Note:** Always set a unique `SECRET_KEY` in production! See [CSRF Configuration](docs/CSRF_CONFIGURATION.md) for details. +> **โ ๏ธ Security Note:** Always set a unique `SECRET_KEY` in production! See [CSRF Configuration](docs/admin/security/CSRF_CONFIGURATION.md) for details. ### Raspberry Pi Deployment TimeTracker runs perfectly on Raspberry Pi 4 (2GB+ RAM): @@ -511,8 +525,8 @@ docker-compose up -d # Prometheus: http://localhost:9090 ``` -**๐ See [Deployment Guide](docs/DOCKER_PUBLIC_SETUP.md) for detailed instructions** -**๐ See [Docker Compose Setup](docs/DOCKER_COMPOSE_SETUP.md) for configuration options** +**๐ See [Deployment Guide](docs/admin/configuration/DOCKER_PUBLIC_SETUP.md) for detailed instructions** +**๐ See [Docker Compose Setup](docs/admin/configuration/DOCKER_COMPOSE_SETUP.md) for configuration options** --- @@ -520,7 +534,7 @@ docker-compose up -d TimeTracker is highly configurable through environment variables. For a comprehensive list and recommended values, see: -- [`docs/DOCKER_COMPOSE_SETUP.md`](docs/DOCKER_COMPOSE_SETUP.md) +- [`docs/admin/configuration/DOCKER_COMPOSE_SETUP.md`](docs/admin/configuration/DOCKER_COMPOSE_SETUP.md) - [`env.example`](env.example) Common settings: @@ -719,7 +733,7 @@ We welcome contributions! Whether it's: - ๐ **Documentation** โ Improve our docs - ๐ป **Code Contributions** โ Submit pull requests -**๐ See [Contributing Guidelines](docs/CONTRIBUTING.md) to get started** +**๐ See [Contributing Guidelines](docs/development/CONTRIBUTING.md) to get started** --- diff --git a/app/__init__.py b/app/__init__.py index 9a0da5e3..9ff4647b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -956,6 +956,7 @@ def create_app(config=None): from app.routes.api_docs import api_docs_bp, swaggerui_blueprint from app.routes.analytics import analytics_bp from app.routes.tasks import tasks_bp + from app.routes.issues import issues_bp from app.routes.invoices import invoices_bp from app.routes.recurring_invoices import recurring_invoices_bp from app.routes.payments import payments_bp @@ -1011,6 +1012,7 @@ def create_app(config=None): app.register_blueprint(swaggerui_blueprint) app.register_blueprint(analytics_bp) app.register_blueprint(tasks_bp) + app.register_blueprint(issues_bp) app.register_blueprint(invoices_bp) app.register_blueprint(recurring_invoices_bp) app.register_blueprint(payments_bp) @@ -1273,6 +1275,7 @@ def create_app(config=None): Settings, TaskActivity, Comment, + Issue, ) # Create database tables @@ -1280,6 +1283,9 @@ def create_app(config=None): # Check and migrate Task Management tables if needed migrate_task_management_tables() + + # Check and migrate Issues table if needed + migrate_issues_table() # Create default admin user if it doesn't exist admin_username = app.config.get("ADMIN_USERNAMES", ["admin"])[0] @@ -1423,6 +1429,32 @@ def migrate_task_management_tables(): print(" The application will continue, but Task Management features may not work properly") +def migrate_issues_table(): + """Check and migrate Issues table if it doesn't exist""" + try: + from sqlalchemy import inspect + + # Check if issues table exists + inspector = inspect(db.engine) + existing_tables = inspector.get_table_names() + + if "issues" not in existing_tables: + print("Issues: Creating issues table...") + # Import Issue model to ensure it's registered + from app.models import Issue + # Create the issues table + Issue.__table__.create(db.engine, checkfirst=True) + print("โ Issues table created successfully") + else: + print("Issues: Issues table already exists") + + print("Issues migration check completed") + + except Exception as e: + print(f"โ Warning: Issues migration check failed: {e}") + print(" The application will continue, but Issues features may not work properly") + + def init_database(app): """Initialize database tables and create default admin user""" with app.app_context(): @@ -1436,6 +1468,7 @@ def init_database(app): Settings, TaskActivity, Comment, + Issue, ) # Create database tables diff --git a/app/models/__init__.py b/app/models/__init__.py index 21acac1c..c10455ca 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -77,6 +77,7 @@ from .expense_gps import MileageTrack from .link_template import LinkTemplate from .custom_field_definition import CustomFieldDefinition from .salesman_email_mapping import SalesmanEmailMapping +from .issue import Issue __all__ = [ "User", @@ -180,4 +181,5 @@ __all__ = [ "LinkTemplate", "CustomFieldDefinition", "SalesmanEmailMapping", + "Issue", ] diff --git a/app/models/client.py b/app/models/client.py index a529c557..9c39fdae 100644 --- a/app/models/client.py +++ b/app/models/client.py @@ -32,6 +32,7 @@ class Client(db.Model): portal_password_hash = db.Column(db.String(255), nullable=True) # Hashed password for portal access password_setup_token = db.Column(db.String(100), nullable=True, index=True) # Token for password setup/reset password_setup_token_expires = db.Column(db.DateTime, nullable=True) # Token expiration time + portal_issues_enabled = db.Column(db.Boolean, default=True, nullable=False) # Enable/disable issue reporting in portal # Custom fields for flexible data storage (e.g., debtor_number, ERP IDs, etc.) custom_fields = db.Column(db.JSON, nullable=True) diff --git a/app/models/issue.py b/app/models/issue.py new file mode 100644 index 00000000..7908eee4 --- /dev/null +++ b/app/models/issue.py @@ -0,0 +1,296 @@ +from datetime import datetime +from app import db +from app.utils.timezone import now_in_app_timezone + + +class Issue(db.Model): + """Issue/Bug Report model for tracking client-reported issues""" + + __tablename__ = "issues" + + id = db.Column(db.Integer, primary_key=True) + client_id = db.Column(db.Integer, db.ForeignKey("clients.id"), nullable=False, index=True) + project_id = db.Column(db.Integer, db.ForeignKey("projects.id"), nullable=True, index=True) + task_id = db.Column(db.Integer, db.ForeignKey("tasks.id"), nullable=True, index=True) + + title = db.Column(db.String(200), nullable=False, index=True) + description = db.Column(db.Text, nullable=True) + status = db.Column( + db.String(20), default="open", nullable=False, index=True + ) # 'open', 'in_progress', 'resolved', 'closed', 'cancelled' + priority = db.Column(db.String(20), default="medium", nullable=False) # 'low', 'medium', 'high', 'urgent' + + # Client submission info + submitted_by_client = db.Column(db.Boolean, default=True, nullable=False) # True if submitted via client portal + client_submitter_name = db.Column(db.String(200), nullable=True) # Name of person who submitted (if not a user) + client_submitter_email = db.Column(db.String(200), nullable=True) # Email of submitter + + # Internal assignment + assigned_to = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=True, index=True) + created_by = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=True, index=True) # Internal user who created/imported + + # Timestamps + created_at = db.Column(db.DateTime, default=now_in_app_timezone, nullable=False) + updated_at = db.Column(db.DateTime, default=now_in_app_timezone, onupdate=now_in_app_timezone, nullable=False) + resolved_at = db.Column(db.DateTime, nullable=True) + closed_at = db.Column(db.DateTime, nullable=True) + + # Relationships + client = db.relationship("Client", backref="issues", lazy="joined") + project = db.relationship("Project", backref="issues", lazy="joined") + task = db.relationship("Task", backref="issues", lazy="joined") + assigned_user = db.relationship("User", foreign_keys=[assigned_to], backref="assigned_issues", lazy="joined") + creator = db.relationship("User", foreign_keys=[created_by], backref="created_issues", lazy="joined") + + def __init__( + self, + client_id, + title, + description=None, + project_id=None, + task_id=None, + priority="medium", + status="open", + submitted_by_client=True, + client_submitter_name=None, + client_submitter_email=None, + assigned_to=None, + created_by=None, + ): + self.client_id = client_id + self.title = title.strip() + self.description = description.strip() if description else None + self.project_id = project_id + self.task_id = task_id + self.priority = priority + self.status = status + self.submitted_by_client = submitted_by_client + self.client_submitter_name = client_submitter_name + self.client_submitter_email = client_submitter_email + self.assigned_to = assigned_to + self.created_by = created_by + + def __repr__(self): + return f"