# Tickets vs Installations - Clarification

## Overview
Both "Tickets" and "Installations" are stored in Odoo's `project.task` model, but they serve different purposes in the portal.

## The Confusion

In Odoo, the `project.task` model is used for:
1. **Support Tickets** - Customer service requests, issues, complaints
2. **Installation Tasks** - Physical installation work for new services

Both use the same underlying data structure but are differentiated by:
- The **project** they belong to
- Their **purpose** and **workflow**
- How they're **displayed** in the portal

## Current Implementation

### Support Tickets (`/support`)
**Purpose**: Customer service and issue resolution

**Data Source**: 
- Odoo `project.task` records
- Filtered by support-related projects
- Can also be created directly in the portal database

**Features**:
- Create new tickets
- Add messages/replies
- Track resolution status
- Rate support quality
- View ticket history

**Typical Use Cases**:
- Technical issues
- Billing questions
- Service faults
- General inquiries

### Installations (`/installations`)
**Purpose**: Track physical installation work for new services

**Data Source**:
- Odoo `project.task` records
- Filtered by installation/deployment projects
- Linked to customer orders

**Features**:
- View installation schedule
- Track installation progress
- See assigned technicians
- Monitor deadlines
- View installation details

**Typical Use Cases**:
- New fiber installation
- Equipment setup
- Service activation
- Site surveys

## How They're Differentiated

### In Odoo
Both are `project.task` records, but:

**Support Tickets**:
- Belong to "Support" or "Helpdesk" projects
- Have support-specific stages (Open, In Progress, Resolved, Closed)
- May have ticket types (Technical, Billing, General, Fault)
- Focus on issue resolution

**Installations**:
- Belong to "Installation" or "Deployment" projects
- Have installation-specific stages (Scheduled, In Progress, Completed)
- Linked to sales orders
- Focus on service delivery

### In the Portal

**Support Page** (`/support`):
```javascript
// Fetches support-related tasks
OdooService::getCustomerTickets($partnerId)
// Filters by support/helpdesk projects
```

**Installations Page** (`/installations`):
```javascript
// Fetches installation-related tasks
OdooService::getCustomerInstallations($partnerId)
// Filters by installation/deployment projects
```

## Backend Implementation

### OdooService Methods

```php
// For Support Tickets
public function getCustomerTickets($partnerId)
{
    // Searches project.task with support project filter
    // Returns tickets for customer service
}

// For Installations
public function getCustomerInstallations($partnerId)
{
    // Searches project.task with installation project filter
    // Returns installation tasks
}
```

### Controllers

**SupportController**:
- Handles ticket creation
- Manages ticket messages
- Tracks ticket status
- Sends notifications

**InstallationController**:
- Displays installation schedule
- Shows installation progress
- Lists assigned technicians
- Tracks deadlines

## Recommended Solution

### Option 1: Filter by Project Type (Current Approach)
Keep both using `project.task` but filter by project:

**Advantages**:
- Uses Odoo's native structure
- No data duplication
- Leverages existing Odoo workflows

**Implementation**:
```php
// In OdooService
public function getCustomerTickets($partnerId)
{
    return $this->searchRead('project.task', [
        ['partner_id', '=', $partnerId],
        ['project_id.name', 'ilike', 'support'], // Filter by project name
    ]);
}

public function getCustomerInstallations($partnerId)
{
    return $this->searchRead('project.task', [
        ['partner_id', '=', $partnerId],
        ['project_id.name', 'ilike', 'installation'], // Filter by project name
    ]);
}
```

### Option 2: Use Tags/Categories
Add tags to differentiate:

**Advantages**:
- More flexible
- Can have tasks that are both
- Easy to filter

**Implementation**:
```php
// Add tag_ids filter
['tag_ids.name', 'in', ['support', 'ticket']]
['tag_ids.name', 'in', ['installation', 'deployment']]
```

### Option 3: Use Custom Fields
Add a custom field `task_type`:

**Advantages**:
- Explicit differentiation
- Clear data model
- Easy to query

**Implementation**:
```php
['task_type', '=', 'support']
['task_type', '=', 'installation']
```

## Current Status

✅ **Implemented**: Both tickets and installations fetch from `project.task`

✅ **Working**: 
- Support tickets display correctly
- Installations display correctly
- Both have separate pages and navigation

⚠️ **Needs Clarification**:
- How to reliably differentiate between tickets and installations in Odoo
- Which projects contain support tickets vs installations
- Whether to use project names, tags, or custom fields for filtering

## Next Steps

1. **Verify Odoo Project Structure**:
   - List all projects in Odoo
   - Identify which projects contain support tickets
   - Identify which projects contain installations

2. **Implement Proper Filtering**:
   - Update `getCustomerTickets()` with correct project filter
   - Update `getCustomerInstallations()` with correct project filter
   - Test both endpoints

3. **Document Project Naming Convention**:
   - Define standard project names for support
   - Define standard project names for installations
   - Update code to use these conventions

## Testing

To verify the current implementation:

```bash
# Test installations API
php test-installations-api.php

# Check what projects exist in Odoo
php test-odoo-projects.php  # (need to create this)

# Verify ticket filtering
php test-support-tickets.php  # (need to create this)
```

## Conclusion

Both tickets and installations use `project.task` in Odoo, which is correct. The key is to properly filter them by project or another differentiating field. The current implementation works, but we need to ensure the filtering logic correctly separates support tickets from installation tasks based on your Odoo project structure.
