Compare commits
20 Commits
2a363c6b40
...
f3766c2898
| Author | SHA1 | Date | |
|---|---|---|---|
| f3766c2898 | |||
| 431052920e | |||
| 1f79cdcaaf | |||
| 8761d0e7c7 | |||
| 0053576cc2 | |||
| 7bd7b8f7c4 | |||
| 3342b57469 | |||
| 1bfa50aa5f | |||
| 85367747a6 | |||
| d7657bb356 | |||
| 9dac39853f | |||
| c1a3b02ac5 | |||
| 1f750a6db4 | |||
| ffcc83d7bd | |||
| 6c3c565440 | |||
| 1c191a54e1 | |||
| 512aedce69 | |||
| f362fbd915 | |||
|
|
35399170b3 | ||
|
|
3b3c57205a |
@@ -1,135 +0,0 @@
|
||||
---
|
||||
description: Use the Fusion API module for all API calls (OpenAI, Anthropic, Google Maps, Twilio, OAuth) in any Fusion module
|
||||
globs: fusion_*/models/**/*.py, fusion_*/services/**/*.py
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
# Fusion API Integration Guide
|
||||
|
||||
When any Fusion module needs to call an external API (OpenAI, Anthropic, Google Maps, Twilio, Google/Microsoft OAuth), it MUST use the centralized `fusion.api.service` instead of managing its own keys.
|
||||
|
||||
The service lives at `fusion_api/models/api_service.py` and is an AbstractModel accessible via `self.env['fusion.api.service']`.
|
||||
|
||||
## Available Methods
|
||||
|
||||
### 1. `call_openai()` -- AI text generation via OpenAI
|
||||
|
||||
```python
|
||||
result = self.env['fusion.api.service'].call_openai(
|
||||
consumer='fusion_clock_ai', # your module's technical name
|
||||
feature='timesheet_summary', # descriptive feature name for tracking
|
||||
messages=[
|
||||
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
||||
{'role': 'user', 'content': 'Summarize this timesheet...'},
|
||||
],
|
||||
model='gpt-4o-mini', # optional, defaults to gpt-4o-mini
|
||||
max_tokens=1024, # optional, defaults to 1024
|
||||
user=self.env.user, # optional, defaults to current user
|
||||
)
|
||||
# Returns: str (the text response)
|
||||
```
|
||||
|
||||
### 2. `call_anthropic()` -- AI text generation via Claude
|
||||
|
||||
```python
|
||||
result = self.env['fusion.api.service'].call_anthropic(
|
||||
consumer='fusion_notes',
|
||||
feature='voice_transcription',
|
||||
messages=[
|
||||
{'role': 'user', 'content': 'Transcribe this text...'},
|
||||
],
|
||||
system='You are a medical transcription assistant.', # optional system prompt
|
||||
model='claude-sonnet-4-20250514', # optional, defaults to claude-sonnet-4-20250514
|
||||
max_tokens=1024, # optional
|
||||
)
|
||||
# Returns: str (the text response)
|
||||
```
|
||||
|
||||
### 3. `get_api_key()` -- raw API key for non-AI services
|
||||
|
||||
```python
|
||||
api_key = self.env['fusion.api.service'].get_api_key(
|
||||
provider_type='google_maps', # one of: google_maps, twilio, custom
|
||||
consumer='fusion_shipping', # your module's technical name
|
||||
feature='geocoding', # optional feature name
|
||||
)
|
||||
# Returns: str (the raw API key to use in your own HTTP calls)
|
||||
```
|
||||
|
||||
### 4. `get_oauth_credentials()` -- OAuth tokens for Google/Microsoft
|
||||
|
||||
```python
|
||||
creds = self.env['fusion.api.service'].get_oauth_credentials(
|
||||
provider_type='google_oauth', # google_oauth or microsoft_oauth
|
||||
consumer='fusion_schedule',
|
||||
feature='calendar_sync',
|
||||
)
|
||||
# Returns: dict with keys:
|
||||
# client_id, client_secret, access_token, refresh_token, token_expiry, redirect_uri
|
||||
```
|
||||
|
||||
## Provider Types
|
||||
|
||||
| Type | Use For |
|
||||
|------|---------|
|
||||
| `openai` | GPT-4o, GPT-4o-mini, o1, etc. |
|
||||
| `anthropic` | Claude Sonnet, Haiku, Opus |
|
||||
| `google_maps` | Geocoding, Places, Distance Matrix |
|
||||
| `google_oauth` | Google Calendar, Drive OAuth |
|
||||
| `microsoft_oauth` | Microsoft Calendar, Graph OAuth |
|
||||
| `twilio` | SMS, Voice |
|
||||
| `custom` | Any other API provider |
|
||||
|
||||
## What Happens Automatically
|
||||
|
||||
- The calling module is auto-registered as a consumer in Fusion API
|
||||
- Every call is logged with: tokens, cost, response time, user, feature, model
|
||||
- Budget caps (monthly/daily) are enforced before each call
|
||||
- Rate limits (RPM/RPD) are enforced before each call
|
||||
- Per-user limits are checked if configured
|
||||
- On limit exceeded, a `UserError` is raised with a clear message
|
||||
|
||||
## Phased Migration Pattern
|
||||
|
||||
Do NOT add `fusion_api` as a hard dependency. Use a try/fallback pattern so the module works with or without Fusion API installed:
|
||||
|
||||
```python
|
||||
def _call_ai(self, messages, feature='general'):
|
||||
"""Call OpenAI through Fusion API, falling back to own key."""
|
||||
try:
|
||||
return self.env['fusion.api.service'].call_openai(
|
||||
consumer='fusion_clock_ai',
|
||||
feature=feature,
|
||||
messages=messages,
|
||||
)
|
||||
except Exception:
|
||||
api_key = self.env['ir.config_parameter'].sudo().get_param(
|
||||
'fusion_clock_ai.openai_api_key'
|
||||
)
|
||||
if not api_key:
|
||||
raise
|
||||
from openai import OpenAI
|
||||
client = OpenAI(api_key=api_key)
|
||||
response = client.chat.completions.create(
|
||||
model='gpt-4o-mini', messages=messages,
|
||||
)
|
||||
return response.choices[0].message.content
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
- NEVER hardcode API keys in Python code
|
||||
- NEVER store API keys in `ir.config_parameter` for new modules -- use Fusion API
|
||||
- ALWAYS pass the module's technical name (e.g. `fusion_clock_ai`) as the `consumer` parameter
|
||||
- ALWAYS pass a descriptive `feature` string for usage tracking granularity
|
||||
- NEVER catch and silently swallow errors from `fusion.api.service` -- let UserError propagate
|
||||
- DO NOT add `fusion_api` to `depends` in `__manifest__.py` -- use the fallback pattern above
|
||||
- The `consumer` string should match the module's technical name exactly (folder name)
|
||||
|
||||
## Odoo 19 Conventions
|
||||
|
||||
- This project targets Odoo 19 (Community/Enterprise)
|
||||
- No hardcoded colors in views or SCSS -- let Odoo handle dark/light theming
|
||||
- Use `res.groups.privilege` for security groups (not `category_id`)
|
||||
- Do not use deprecated `ir.cron` fields (`numbercall`, `doall`)
|
||||
- Settings views: use `name=` attribute on `<app>` tags, not `data-key=`
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/__pycache__/
|
||||
*.pyc
|
||||
40
CLAUDE.md
40
CLAUDE.md
@@ -1,40 +0,0 @@
|
||||
# Odoo Modules — Claude Code Instructions
|
||||
|
||||
## Project
|
||||
27 custom Odoo 19 modules for Fusion Central (Westin Healthcare + NEXA Systems).
|
||||
|
||||
## Critical Rules — Odoo 19
|
||||
1. **NEVER code from memory** — Always read a reference file from Docker first:
|
||||
```bash
|
||||
docker exec odoo-dev-app cat /usr/lib/python3/dist-packages/odoo/addons/<module>/static/src/<path>
|
||||
```
|
||||
2. **Frontend JS**: Use `Interaction` class from `@web/public/interaction`, registered via `registry.category("public.interactions")`. NOT IIFE/DOMContentLoaded.
|
||||
3. **Backend OWL**: Use standalone `rpc()` from `@web/core/network/rpc`. NOT `useService("rpc")`. `static props = []` not `{}`.
|
||||
4. **HTTP routes**: `type="jsonrpc"` — NOT `type="json"` (deprecated).
|
||||
5. **res.config.settings**: Only boolean/integer/float/char/selection/many2one/datetime. NO Date fields.
|
||||
6. **res.groups**: NO `users` field, NO `category_id` field.
|
||||
7. **Search views**: NO `group expand="0"` syntax.
|
||||
|
||||
## Naming
|
||||
- New fields: `x_fc_*` prefix
|
||||
- Legacy fields: `x_studio_*`
|
||||
- Canadian English for all user-facing text
|
||||
- Currency: `$` sign with Monetary fields + currency_id
|
||||
|
||||
## Cursor-Managed Modules
|
||||
- **fusion_clock** is currently being modified in Cursor — always read files fresh before editing, don't assume you know the current state
|
||||
|
||||
## Workflow
|
||||
- Local dev: `docker exec odoo-dev-app odoo -d fusion-dev -u <module> --stop-after-init`
|
||||
- Local URL: http://localhost:8069
|
||||
- Test before deploying. Edit existing files — don't create unnecessary new ones.
|
||||
|
||||
## Supabase Knowledge Base
|
||||
Before starting unfamiliar work, check Supabase for context:
|
||||
```bash
|
||||
PGPASSWORD='a09e12e0995dc29446631fa458f3d4b3' psql -h 100.74.28.73 -p 5433 -U postgres -d postgres
|
||||
```
|
||||
- `fusionapps.decisions` — past architecture decisions
|
||||
- `fusionapps.issues` — known issues and fixes
|
||||
- `fusionapps.code_snippets` — reference code
|
||||
- `fusionapps.quick_commands` — deployment and admin commands
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user