Skip to content

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, readonly and required.

Get started ​

  1. Open an XML file in an Odoo module.
  2. Type odoo and the name of what you need, for example odoo form view.
  3. Pick the snippet from the list. Use the arrow keys to move, press Enter or Tab to insert it, and press Esc to close the list.
  4. Press Tab to 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 ​

SnippetWhat it inserts
odoo xmlAn XML file with the UTF-8 declaration and an <odoo> root.
odoo recordA <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.

SnippetWhat it inserts
odoo form viewA form with a sheet, a title and a group.
odoo list viewA list view.
odoo editable listAn inline-editable list, with a choice of bottom or top. Odoo 20 only.
odoo search viewA search view with a filter and a group-by.
odoo kanban viewA kanban view. It uses the card template.
odoo calendar viewA calendar with start and stop dates, a mode and a color field.
odoo graph viewA graph. Choose bar, line or pie.
odoo pivot viewA pivot view with a row and a column.
odoo view inheritAn inherited view with an xpath. Choose the position.
odoo xpathAn xpath block. Choose after, before, inside, replace or attributes.

View parts ​

SnippetWhat it inserts
odoo sheetA sheet with a group and a field.
odoo headerA form header with two buttons and the status bar.
odoo notebookA notebook with one page.
odoo pageA single notebook page.
odoo chatterThe chatter. The model must inherit mail.thread.
odoo button boxThe container for smart buttons.
odoo smart buttonA 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 buttonA button that calls a model method.
odoo action buttonA button that opens an action.
odoo labelA field label.
odoo ribbonThe ribbon widget, with a color choice. Odoo 20 only.

Fields and attributes ​

SnippetWhat it inserts
odoo fieldA field.
odoo field widgetA field with a widget. Choose from many2many_tags, many2one_avatar_user, badge, priority, boolean_toggle, handle, monetary, image, html, progressbar and more.
odoo field invisibleA field hidden by a condition.
odoo field readonlyA field made read-only by a condition.
odoo field requiredA field made required by a condition.
odoo field stateThe status bar field.
odoo column invisibleA list column hidden by a condition on the parent. Odoo 20 only.
odoo field optionalA list column the user can show or hide. Odoo 20 only.
odoo domainA domain attribute.
odoo optionsAn options attribute.
odoo groupsA groups attribute.

Actions, menus and data ​

SnippetWhat it inserts
odoo actionA window action with a "no content" help message.
odoo menu rootAn app menu with an icon.
odoo menu categoryA menu with sub-menus.
odoo menu actionA menu that opens an action.
odoo accessAn access right with ir.access. Odoo 20 only.
odoo cronA scheduled action that calls a model method. Choose the interval type. Odoo 20 only.
odoo reportA PDF report action. Odoo 20 only.
odoo settingsAn 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 xpath position, 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. The attrs and states attributes are not used.
  • Use odoo menu root, odoo menu category and odoo menu action in that order to build a menu tree. Set parent on 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 report and odoo settings snippets are only offered on Odoo 20.

Next steps ​

Built by Cybrosys Technologies.