Test Odoo API connection and sync functionality to diagnose issues. ## What this command does: - Validates Odoo connection credentials - Tests API authentication - Verifies model access and permissions - Checks sync functionality - Runs diagnostic tests on cache stores - Provides detailed error reporting and solutions ## Prerequisites: Before testing, ensure: 1. โœ… `.env` file exists and is configured 2. โœ… Current directory is an Odoo PWA project 3. โœ… Development server can be started 4. โœ… Internet connection is available ## Diagnostic Tests to Run: ### 1. Environment Configuration Check Verify all required environment variables are set: - `VITE_ODOO_URL` - Odoo instance URL - `VITE_ODOO_DB` - Database name - `ODOO_API_KEY` - API authentication key - `ODOO_USERNAME` - User email/username - `VITE_MODEL_NAME` - Primary model name ### 2. Network Connectivity Test ```bash # Test if Odoo URL is reachable curl -I [ODOO_URL] ``` Expected: HTTP 200 or 301/302 redirect ### 3. API Authentication Test Make a test API call to verify credentials: ```javascript POST /api/odoo { "action": "search", "model": "res.partner", "domain": [], "fields": ["id", "name"], "limit": 1 } ``` Expected: Returns at least one partner record ### 4. Model Access Test Verify the configured model exists and is accessible: ```javascript POST /api/odoo { "action": "search_model", "model": "[VITE_MODEL_NAME]", "domain": [], "fields": ["id"], "limit": 1 } ``` Expected: Returns records or empty array (not an error) ### 5. CRUD Operations Test Test each operation: - **Create**: Create a test record - **Read**: Fetch the created record - **Update**: Modify the record - **Delete**: Remove the test record ### 6. Cache Functionality Test Verify cache stores work correctly: - localStorage read/write - IndexedDB read/write - Cache expiration logic - Sync mechanism ### 7. Sync Performance Test Measure sync performance: - Initial load time - Incremental sync time - Number of records synced - Network request count ## Steps: 1. Read and validate `.env` file 2. Parse environment variables 3. Run each diagnostic test in sequence 4. Log results with timestamps 5. Identify failing tests 6. Provide specific solutions for failures 7. Generate diagnostic report ## Output Format: ``` ๐Ÿงช Odoo PWA Connection Diagnostics ================================ โœ… Environment Configuration: PASSED - ODOO_URL: https://yourcompany.odoo.com - DATABASE: yourcompany-main - MODEL: x_expense โœ… Network Connectivity: PASSED - Odoo server reachable - Response time: 234ms โœ… API Authentication: PASSED - API key valid - User authenticated: your.email@company.com โœ… Model Access: PASSED - Model exists: x_expense - Read permission: Yes - Write permission: Yes โœ… CRUD Operations: PASSED - Create: โœ… Record created (ID: 123) - Read: โœ… Record fetched - Update: โœ… Record updated - Delete: โœ… Record deleted โœ… Cache Functionality: PASSED - localStorage: Working - IndexedDB: Working - Sync interval: 3 minutes โœ… Sync Performance: PASSED - Initial load: 1.2s (45 records) - Incremental sync: 0.3s (2 new records) - Network requests: 3 ================================ ๐ŸŽ‰ All tests passed! Your Odoo PWA is working correctly. ``` ## Example prompts to use this command: - `/test-connection` - Run full diagnostic suite - User: "Test my Odoo connection" - User: "Why isn't data syncing from Odoo?" - User: "Diagnose Odoo API issues" ## Common Issues and Solutions: ### โŒ Connection Failed **Error**: Cannot reach Odoo URL **Solutions**: - Verify URL is correct (include https://) - Check internet connection - Test URL in browser - Check firewall/VPN settings ### โŒ Authentication Failed **Error**: Invalid API key or credentials **Solutions**: - Regenerate API key in Odoo (Settings โ†’ Users โ†’ API Keys) - Verify username matches API key owner - Check for typos in `.env` file - Ensure API key has not expired ### โŒ Model Not Found **Error**: Model doesn't exist or no access **Solutions**: - Verify model exists in Odoo Studio - Check model name includes `x_` prefix - Verify user has read/write permissions - Check model is published (not in draft mode) ### โŒ CORS Error **Error**: Blocked by CORS policy **Solutions**: - Use server-side API proxy (recommended) - Configure CORS in Odoo (not recommended) - Check API route is working correctly ### โŒ Sync Not Working **Error**: Records not updating **Solutions**: - Check browser console for errors - Verify sync interval is running - Clear cache and try again - Check Odoo server is not down ### โŒ Permission Denied **Error**: Cannot create/update records **Solutions**: - Verify user has write permission on model - Check required fields are included - Verify field types match expectations - Check for validation rules in Odoo ## Development Tools: Provide user with helpful commands: ```bash # Watch network requests # Open browser DevTools โ†’ Network tab # View cache contents localStorage.getItem('[model]Cache') # Force cache clear localStorage.clear() # Monitor sync in console # Look for "Syncing..." messages ``` ## After Testing: If all tests pass: - Confirm the application is working correctly - Suggest running tests periodically - Recommend monitoring in production If tests fail: - Provide specific error messages - Offer step-by-step troubleshooting - Suggest checking Odoo server logs - Offer to help fix configuration ## Advanced Diagnostics: For complex issues: 1. Export full diagnostic report 2. Check Odoo server logs 3. Review browser console errors 4. Analyze network traffic 5. Test with different API keys 6. Try with different models 7. Compare with working examples