unclecatvn/agent-skills / skills/odoo-19.0
odoo-19
VerifiedOdoo 19 development knowledge base with 18 specialized guides covering Actions (ir.actions.*, cron jobs, server actions), Controllers (HTTP routing, endpoints, auth types), Data files (XML/CSV records, shortcuts, noupdate), API Decorators (@api.depends, @api.constrains, @api.ondelete, @api.onchange, @api.model, @api.private), SQL Constraints (models.Constraint replacing _sql_constraints), Database Indexes (models.Index), Module development (manifest, wizards, reports), Field types (Char, Text, Monetary, relational fields), Manifest configuration (__manifest__.py, dependencies, asset bundles), Mixins (mail.thread, mail.activity.mixin, mail.alias.mixin, utm.mixin), ORM Model methods (search, CRUD, domain filters, recordsets, CamelCase model naming), Migration scripts (pre/post/end hooks, data migration), OWL frontend components (hooks, services, lifecycle), Performance optimization (N+1 prevention, batch ops, _read_group), QWeb Reports (PDF/HTML, paper formats, barcodes, t-out), Security/ACL (record rules, field permissions, privilege-based groups, @api.private), Testing (TransactionCase, HttpCase, mocking, query count assertions), Transactions (savepoints, UniqueViolation, serialization failures), Translations (i18n, PO files, translatable fields), XML Views (list/form/search, kanban card templates, xpath inheritance, QWeb templates). Use when writing, reviewing, or debugging any Odoo 19 Python or XML code, creating or modifying modules, fixing performance issues, or looking up Odoo 19 API patterns and best practices. Includes CSS/SCSS asset authoring and review for Odoo addons.
references/odoo-19-owl-guide.md
View on GitHub# Odoo 19 OWL Guide
Guide for building OWL (Owl Web Library) components in Odoo 19.
## Table of Contents
- [OWL Overview](#owl-overview)
- [Component Structure](#component-structure)
- [Hooks](#hooks)
- [Services](#services)
- [State Management](#state-management)
- [QWeb Templates](#qweb-templates)
- [Translations](#translations)
---
## OWL Overview
OWL is a JavaScript framework for building web UI components in Odoo.
### Key Concepts
| Concept | Description |
| ------------- | -------------------------- |
| **Component** | Reusable UI building block |
| **State** | Reactive data |
| **Props** | Component properties |
| **Hooks** | Lifecycle functions |
| **Template** | QWeb template |
---
## Component Structure
### Basic Component
```javascript
import { Component } from "@odoo/owl";
export class MyComponent extends Component {
static template = "my_module.MyComponent";
static props = {
title: { type: String, optional: true },
value: { type: String, optional: true },
};
setup() {
// Component setup
}
}
```
### Register Component
```javascript
import { registry } from "@web/core/registry";
registry.category("actions").add("my_component", MyComponent);
```
### Use in View
```xml
<widget name="my_component" options="{'value': 'Hello'}"/>
```
---
## Hooks
### Setup Hook
Called when component is created:
```javascript
setup() {
// Initialize state
this.state = useState({ count: 0 });
// Call services
this.rpc = useService("rpc");
this.orm = useService("orm");
this.action = useService("action");
}
```
### Lifecycle Hooks
| Hook | When |
| ----------------- | --------------------- |
| `setup()` | Component creation |
| `onWillStart()` | Before render (async) |
| `onMounted()` | After render |
| `onWillUnmount()` | Before destroy |
| `onWillPatch()` | Before update |
| `onPatched()` | After update |
### Example
```javascript
setup() {
onWillStart(this.onWillStart);
onMounted(this.onMounted);
onWillUnmount(this.onWillUnmount);
}
async onWillStart() {
// Load data before render
}
onMounted() {
// After render
}
onWillUnmount() {
// Cleanup
}
```
---
## Services
### Common Services
| Service | Description |
| -------------- | ------------------- |
| `orm` | Database operations |
| `rpc` | RPC calls |
| `action` | Execute actions |
| `dialog` | Show dialogs |
| `notification` | Show notifications |
| `router` | Navigation |
| `user` | Current user |
| `company` | Current company |
### Use Service
```javascript
setup() {
this.orm = useService("orm");
this.rpc = useService("rpc");
this.action = useService("action");
this.dialog = useService("dialog");
this.notification = useService("notification");
}
```
### ORM Service
```javascript
// Search
const records = await this.orm.search("my.model", [["active", "=", true]]);
// Read
const data = await this.orm.read("my.model", ids, ["name", "value"]);
// Create
const id = await this.orm.create("my.model", { name: "Test" });
// Write
await this.orm.write("my.model", [id], { name: "Updated" });
// Unlink
await this.orm.unlink("my.model", [id]);
```
### RPC Service
```javascript
// Call controller
const result = await this.rpc("/my/controller", { param: "value" });
```
### Action Service
```javascript
// Do action
await this.action.doAction({
type: "ir.actions.act_window",
res_model: "my.model",
views: [
[false, "list"],
[false, "form"],
],
});
```
### Dialog Service
```javascript
// Add dialog
this.dialog.add(MyDialog, {
title: "My Dialog",
confirm: () => {...},
});
```
### Notification Service
```javascript
// Show notification
this.notification.notify({
message: "Success!",
type: "success",
});
```
---
## State Management
### useState
```javascript
setup() {
this.state = useState({
count: 0,
name: "",
});
}
increment() {
this.state.count++;
}
```
### useState in Template
```xml
<div t-out="state.count"/>
<button t-on-click="increment">+</button>
```
### Computed State
```javascript
setup() {
this.state = useState({count: 0});
}
get double() {
return this.state.count * 2;
}
```
---
## QWeb Templates
### Basic Template
```xml
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="my_module.MyComponent" owl="1">
<div class="my_component">
<h1 t-out="props.title"/>
<p t-out="state.message"/>
</div>
</t>
</templates>
```
### Event Handlers
```xml
<button t-on-click="increment">Increment</button>
<input t-on-change="onChange"/>
```
### Loops and Conditions
```xml
<!-- Loop -->
<div t-foreach="state.records" t-as="record" t-key="record.id">
<span t-out="record.name"/>
</div>
<!-- Condition -->
<div t-if="state.show">Visible when true</div>
<div t-else="">Visible when false</div>
```
---
## Translations
### Translate in JavaScript
```javascript
import { _t } from "@web/core/l10n/translation";
this.message = _t("Hello World");
```
### Translate with Parameters
```javascript
this.message = _t("Hello %(name)s", { name: "John" });
```
### Translate in Template
```xml
<!-- Static text in OWL templates is extracted and translated; there is no translate() helper -->
<span>Hello World</span>
```
---
## Examples
### Counter Component
```javascript
import { Component, useState } from "@odoo/owl";
import { _t } from "@web/core/l10n/translation";
export class Counter extends Component {
static template = "my_module.Counter";
setup() {
this.state = useState({ count: 0 });
}
increment() {
this.state.count++;
}
decrement() {
this.state.count--;
}
}
```
```xml
<templates xml:space="preserve">
<t t-name="my_module.Counter" owl="1">
<div class="counter">
<button class="btn btn-secondary" t-on-click="decrement">-</button>
<span t-out="state.count"/>
<button class="btn btn-secondary" t-on-click="increment">+</button>
</div>
</t>
</templates>
```
### Data Loading Component
```javascript
import { Component, useState, onWillStart } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
export class DataComponent extends Component {
static template = "my_module.DataComponent";
setup() {
this.orm = useService("orm");
this.state = useState({
records: [],
loading: true,
});
onWillStart(this.loadData);
}
async loadData() {
this.state.records = await this.orm.search("my.model", [], {
limit: 10,
});
this.state.loading = false;
}
}
```
---
## Best Practices
### Use Hooks for Side Effects
```javascript
setup() {
onMounted(() => {
// Side effects here
});
}
```
### Cleanup Resources
```javascript
setup() {
onWillUnmount(() => {
// Cleanup here
});
}
```
### Avoid Direct DOM Manipulation
Use templates and reactive state instead.
### Split Components
Keep components small and focused.
```javascript
// Good: Small focused component
export class UserName extends Component {
static template = "my_module.UserName";
}
// Bad: Large monolithic component
export class Everything extends Component {
static template = "my_module.Everything";
}
```
---
## References
- OWL documentation
- Odoo 19 Web framework docs
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |