XML snippets
Type odoo and a few words in an XML file, then pick a snippet to insert a view, an action, a menu or another data record. The code follows the Odoo version of your project.
These snippets come from the bundled Odoo Helper and support Odoo 18, 19 and 20.
What you can do
- Insert a view of any type, such as form, list, kanban, search, calendar, graph or pivot.
- Add view parts such as a sheet, notebook, chatter or smart button.
- Create actions and menus with the usual fields filled in.
- Extend a view with a view inherit and an
xpath. - Add field conditions for
invisible,readonlyandrequired.
Get started
- Open an XML file in an Odoo module.
- Type
odooand the name of what you need, for exampleodoo form view. - Pick the snippet from the list. Use the arrow keys to move, press
EnterorTabto insert it, and pressEscto close the list. - Press
Tabto jump to each placeholder and fill it in.
Check the version in the status bar, for example Odoo v20 (Auto). Select it to change it.
Common tags and records
| Snippet | What it inserts |
|---|---|
odoo xml | An XML file with the UTF-8 declaration and an <odoo> root. |
odoo record | A <record> with an ID, a model and one field. |
Views
Each view snippet inserts a full ir.ui.view record with the ID and name set from the model name you type.
| Snippet | What it inserts |
|---|---|
odoo form view | A form with a sheet, a title and a group. |
odoo list view | A list view. |
odoo editable list | An inline-editable list, with a choice of bottom or top. Odoo 20 only. |
odoo search view | A search view with a filter and a group-by. |
odoo kanban view | A kanban view. It uses the card template. |
odoo calendar view | A calendar with start and stop dates, a mode and a color field. |
odoo graph view | A graph. Choose bar, line or pie. |
odoo pivot view | A pivot view with a row and a column. |
odoo view inherit | An inherited view with an xpath. Choose the position. |
odoo xpath | An xpath block. Choose after, before, inside, replace or attributes. |
View parts
| Snippet | What it inserts |
|---|---|
odoo sheet | A sheet with a group and a field. |
odoo header | A form header with two buttons and the status bar. |
odoo notebook | A notebook with one page. |
odoo page | A single notebook page. |
odoo chatter | The chatter. The model must inherit mail.thread. |
odoo button box | The container for smart buttons. |
odoo smart button | A smart button with a counter. On Odoo 20 the icon is a Material Symbols name. On 18 and 19 it is a fa- icon. |
odoo object button | A button that calls a model method. |
odoo action button | A button that opens an action. |
odoo label | A field label. |
odoo ribbon | The ribbon widget, with a color choice. Odoo 20 only. |
Fields and attributes
| Snippet | What it inserts |
|---|---|
odoo field | A field. |
odoo field widget | A field with a widget. Choose from many2many_tags, many2one_avatar_user, badge, priority, boolean_toggle, handle, monetary, image, html, progressbar and more. |
odoo field invisible | A field hidden by a condition. |
odoo field readonly | A field made read-only by a condition. |
odoo field required | A field made required by a condition. |
odoo field state | The status bar field. |
odoo column invisible | A list column hidden by a condition on the parent. Odoo 20 only. |
odoo field optional | A list column the user can show or hide. Odoo 20 only. |
odoo domain | A domain attribute. |
odoo options | An options attribute. |
odoo groups | A groups attribute. |
Actions, menus and data
| Snippet | What it inserts |
|---|---|
odoo action | A window action with a "no content" help message. |
odoo menu root | An app menu with an icon. |
odoo menu category | A menu with sub-menus. |
odoo menu action | A menu that opens an action. |
odoo access | An access right with ir.access. Odoo 20 only. |
odoo cron | A scheduled action that calls a model method. Choose the interval type. Odoo 20 only. |
odoo report | A PDF report action. Odoo 20 only. |
odoo settings | An app, block and setting for the settings form. Odoo 20 only. |
Examples
These are Odoo 20 outputs.
odoo form view:
xml
<record id="model_name_view_form" model="ir.ui.view">
<field name="name">model.name.view.form</field>
<field name="model">model.name</field>
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_title">
<h1><field name="name" placeholder="Name"/></h1>
</div>
<group>
<group>
<field name="name"/>
</group>
</group>
</sheet>
</form>
</field>
</record>odoo kanban view:
xml
<record id="model_name_view_kanban" model="ir.ui.view">
<field name="name">model.name.view.kanban</field>
<field name="model">model.name</field>
<field name="arch" type="xml">
<kanban sample="1">
<templates>
<t t-name="card">
<field name="name" class="fw-bold fs-5"/>
</t>
</templates>
</kanban>
</field>
</record>odoo header:
xml
<header>
<button name="action_confirm" string="Confirm" type="object" class="btn-primary" invisible="state != 'draft'"/>
<button name="action_cancel" string="Cancel" type="object" invisible="state not in ('draft', 'confirmed')"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done"/>
</header>odoo view inherit:
xml
<record id="model_name_view_form_inherit" model="ir.ui.view">
<field name="name">model.name.view.form.inherit</field>
<field name="model">model.name</field>
<field name="inherit_id" ref="module.view_id"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="new_field"/>
</xpath>
</field>
</record>odoo action:
xml
<record id="action_model_name" model="ir.actions.act_window">
<field name="name">Action Name</field>
<field name="res_model">model.name</field>
<field name="view_mode">list,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create your first record!
</p>
</field>
</record>odoo access:
xml
<record id="access_model_name_user" model="ir.access">
<field name="name">model.name user</field>
<field name="model_id" ref="model_model_name"/>
<field name="group_id" ref="base.group_user"/>
<field name="operation">crud</field>
<field name="domain">[(1, '=', 1)]</field>
</record>Tips and limits
- Choice lists, such as the graph type, the calendar mode, the field widget and the
xpathposition, are offered on Odoo 20. On Odoo 18 and 19 the same snippets insert a simpler version with a fixed value that you edit. - Conditions such as
invisible="state != 'draft'"are plain expressions. Theattrsandstatesattributes are not used. - Use
odoo menu root,odoo menu categoryandodoo menu actionin that order to build a menu tree. Setparenton the action menu to the ID of its category. - If a snippet you expect is missing, check the version in the status bar. The
odoo access,odoo cron,odoo reportandodoo settingssnippets are only offered on Odoo 20.
Next steps
- Use Python snippets for models and methods.
- Get context-aware suggestions as you type.
- Create modules and files.