# Odoo Actions And Buttons

> Define buttons in views and link them to Python methods or Window Actions. Use when this capability is needed.

- Skill: `tomevault-io/odoo-actions-and-buttons` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/odoo-actions-and-buttons`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/odoo-actions-and-buttons/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/odoo-actions-and-buttons

---


# Odoo Actions and Buttons

## Goal
Add interactivity to the UI using buttons that trigger Python code or other actions.

## 1. Adding Buttons to Views
Buttons are usually placed in the `<header>` of a form view or inside the `<sheet>`/`<list>`.

**Example (Header Button):**
```xml
<form>
    <header>
        <button name="action_sold" type="object" string="Sold" class="oe_highlight"/>
        <button name="action_cancel" type="object" string="Cancel"/>
    </header>
    <sheet>
        <!-- Fields -->
    </sheet>
</form>
```
*   `string`: Label of the button.
*   `class="oe_highlight"`: Highlights the button (primary color).

## 2. Button Types

### Type "object"
Triggers a Python method on the model.
*   **XML:** `type="object"`, `name="method_name"`
*   **Python:** Define a public method (no underscore prefix).

**Example:**
```python
def action_sold(self):
    for record in self:
        if record.state == 'canceled':
            raise UserError("Canceled properties cannot be sold.")
        record.state = 'sold'
    return True
```
*   **Exceptions:** Use `odoo.exceptions.UserError` to stop execution and warn the user.
*   **Return:** Always return `True` (or an action dictionary) for public methods.

### Type "action"
Triggers a specific Window Action (e.g., open a wizard, report, or another view).
*   **XML:** `type="action"`, `name="%(module_name.action_xml_id)d"`

**Example:**
```xml
<button type="action" name="%(estate.action_estate_offer)d" string="Offers"/>
```

## 3. Object Buttons inside Lists
You can add buttons to list views (or inside form sheets).
*   **Icon Buttons:** Use `icon="fa-check"` (FontAwesome) instead of `string` for compact buttons.

**Example:**
```xml
<list>
    <field name="name"/>
    <button name="action_confirm" type="object" icon="fa-check" title="Confirm"/>
    <button name="action_cancel" type="object" icon="fa-times" title="Cancel"/>
</list>
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/itobetter) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

