This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Odoo LLM Integration - A suite of Odoo 18.0 modules for integrating Large Language Models with Odoo ERP. Provides AI-powered chat, knowledge management (RAG), tool execution, and content generation.
# Format and lint Python
ruff format . && ruff check . --fix --unsafe-fixes
# Run pre-commit hooks (includes ESLint, Prettier, Ruff)
pre-commit run --all-files# Run tests for specific module(s)
./run_tests.sh llm_replicate
# Run multiple modules
./run_tests.sh "llm_replicate,llm_comfyui"
# With custom database and port
./run_tests.sh llm_replicate my_test_db 8072
# Direct odoo-bin command for single module
odoo-bin --test-enable --stop-after-init --test-tags=llm -d test_db -u llmllm (base) → llm_thread (chat) → llm_tool (actions) → llm_assistant (AI assistants)
↘ llm_store (vector abstraction) → llm_knowledge (RAG) → llm_pgvector/chroma/qdrant
↘ llm_generate (content generation) → llm_generate_job (async queue)
All inherit from llm.provider and implement provider-specific API calls:
- Text/Chat:
llm_openai,llm_ollama,llm_mistral - Image:
llm_replicate,llm_fal_ai,llm_comfyui,llm_comfy_icu
<!-- Use <list> not <tree> -->
<list string="Records">...</list>
<!-- Use direct attributes, not attrs -->
<field name="x" invisible="not active"/>
<!-- Use invisible, not states for buttons -->
<button invisible="state != 'draft'"/>Odoo 18 replaced the frontend model system completely:
// ❌ OLD (doesn't exist in 18.0)
import { registerModel, registerPatch } from "@mail/model/model_core";
// ✅ NEW - ES6 classes extending Record
import { Record } from "@mail/core/common/record";
import { patch } from "@web/core/utils/patch";
import { rpc } from "@web/core/network/rpc";
// Patch existing components
patch(SomeComponent.prototype, {
setup() {
super.setup();
// ...
},
});// Thread access
mailStore.Thread.get({ model: "llm.thread", id: threadId });
// Message insertion (must also add to thread.messages for UI)
mailStore.insert({ "mail.message": [messageData] }, { html: true });
if (!thread.messages.some((m) => m.id === message.id)) {
thread.messages.push(message);
}from odoo.addons.mail.tools.discuss import Store
def to_store_format(self, message):
store = Store()
message._to_store(store)
return store.get_result()['mail.message'][0]name_get()→ use_compute_display_name()/display_namefieldmessage_format()→ use_to_store()with Store systemfrom odoo import registry→ usefrom odoo.modules.registry import Registry
- User sends message →
message_post()withllm_role="user"→ saved to DB generate_messages()called →get_llm_messages()retrieves history- Full history passed to LLM provider → streaming response via EventSource
- Assistant messages processed through
_process_llm_body()(markdown→HTML) - Tool messages use
body_jsonfield, no HTML processing
When editing static/description/index.html files:
- Use HTML fragments only (no DOCTYPE, html, head, body)
- No rgba() colors - hex only
- No CSS transitions, transforms, animations, or linear-gradients
- No inline JavaScript
- Use Bootstrap 5 grid (container, row, col-*)
- Use inline styles for colors/typography
See ODOO_APP_STORE_HTML_GUIDE.md for details.
- Extract shared logic into base classes or mixins (e.g.,
llm.providerbase for all providers) - Use
_dispatch()pattern for extensible behavior instead of duplicating logic - Common UI components go in base modules, extended via
patch()in feature modules - Shared utilities belong in
llmbase module, not duplicated across provider modules
- Inherit, don't copy: Use
_inheritto extend models, don't duplicate code - Use computed fields: Prefer
@api.dependsover manual updates - Recordsets over IDs: Pass recordsets between methods, not raw IDs
- Context for options: Use
self.with_context()for optional behavior, not extra parameters - SQL only when necessary: Use ORM unless performance requires raw SQL (then add
_flush()) - Security by design: Define proper access rules, use
sudo()sparingly and explicitly - Transactional safety: Use
cr.savepoint()for operations that might fail partially
Keep core logic independent of specific LLM providers:
# ✅ Good - provider-agnostic interface
class LlmThread(models.Model):
def generate_messages(self):
return self.model_id.provider_id.chat(messages) # Provider handles specifics
# ❌ Bad - provider-specific code in core
class LlmThread(models.Model):
def generate_messages(self):
if self.provider_id.provider == 'openai':
client = OpenAI(api_key=...) # Don't do this in core!- All provider-specific logic lives in provider modules (
llm_openai,llm_ollama, etc.) - Core modules define interfaces via abstract methods or dispatch hooks
- Use
_dispatch(event_name, **kwargs)for provider-specific transformations - External API clients are instantiated only in provider modules
# Base module defines hook
class LlmProvider(models.Model):
def chat(self, messages, **kwargs):
messages = self._dispatch("normalize_messages", messages=messages)
return self._chat(messages, **kwargs) # Abstract, implemented by providers
# Provider module implements
class LlmProviderOpenAI(models.Model):
_inherit = "llm.provider"
def _chat(self, messages, **kwargs):
# OpenAI-specific implementation| Module | Python Dependencies |
|---|---|
llm_knowledge |
requests, markdownify, PyMuPDF, numpy |
llm_pgvector |
pgvector, numpy |
llm_chroma |
chromadb-client, numpy |
llm_qdrant |
qdrant-client |
llm_knowledge_llama |
llama_index, nltk |
llm_openai |
openai |
llm_ollama |
ollama |
llm_mistral |
mistralai |
- Python: Ruff with Odoo-specific isort sections (odoo → odoo.addons → first-party)
- JavaScript: ESLint with strict rules (no-shadow, valid-jsdoc, sort-imports)
- Max complexity: Python 16, JavaScript 15