# Order Tracking Fix for Odoo Orders

## Problem
Order tracking was disabled for Odoo orders because the `OrderWorkflowController::getOrderStatus()` method couldn't handle Odoo order numbers (like `DFAZ-SO-1503`). It only worked with numeric IDs or portal order numbers.

## Solution
Updated `OrderWorkflowController::getOrderStatus()` to detect and handle Odoo order numbers similar to how `SalesOrderController::show()` works.

### Changes Made

1. **Odoo Order Detection**
   - Detects if `$orderId` is an Odoo order number (not numeric and doesn't start with `AFINET-SO-`)
   - Fetches order from Odoo if customer has `odoo_partner_id`

2. **Order Transformation**
   - Transforms Odoo order data to match portal format
   - Maps Odoo statuses to portal statuses using helper methods
   - Provides tracking info compatible with frontend

3. **Helper Methods Added**
   - `mapOdooOrderStatus()` - Maps Odoo state to portal order_status
   - `mapOdooInvoiceStatus()` - Maps Odoo invoice_status to portal payment_status
   - `formatOdooAddress()` - Extracts address from Odoo partner data

### Status Mapping

#### Order Status
- `draft`, `sent` → `pending`
- `sale` → `completed`
- `done` → `completed`
- `cancel` → `cancelled`

#### Payment Status
- `invoiced` → `paid`
- `to invoice` → `pending`
- `no` → `pending`

## Frontend Integration

The frontend already passes the correct identifier:
```javascript
// In orders/page.js
<Link
  href={`/orders/tracking?orderId=${order.source === 'odoo' ? order.order_number : order.id}`}
  className="text-purple-600 hover:text-purple-900"
  title="Track Order"
>
  <Package className="h-4 w-4" />
</Link>
```

## Testing

Test with both order types:
1. **Odoo Order**: `/orders/tracking?orderId=DFAZ-SO-1503`
2. **Portal Order**: `/orders/tracking?orderId=123` (numeric ID)

## Files Modified
- `afinet-portal-backend/app/Http/Controllers/API/OrderWorkflowController.php`

## Related Documentation
- `ODOO_ORDER_VIEWING.md` - View Details functionality
- `UNIFIED_ORDER_SYSTEM.md` - Order creation and sync
- `ORDER_DISPLAY_CHANGES.md` - Frontend display changes
