Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 39 ยท Views and QWeb

Odoo Views and the XML Architecture

Learn how Odoo describes screens as XML records: the ir.ui.view model, the arch field, the main view types, view modes in actions and how the web client loads them.

In Odoo you do not write HTML pages for the screens people use every day. You describe them. A view is a small XML document that says "show these fields, in this layout, as a list or a form or a board of cards", and the web client turns that description into an interface. Because the description is data stored in the database, other modules can modify it without touching your code, which is what makes Odoo so customisable.

This lesson explains where views live, what the main view types are and how an action decides which ones to open. The real Odoo framework cannot run on this site, so every Odoo snippet below is read-only and the runnable examples are small Python stand-ins that model the same ideas with the standard library.

A view is a record

Views are rows of the model ir.ui.view. You normally create them from an XML data file in your module:

XML
<odoo>
  <record id="view_library_book_form" model="ir.ui.view">
    <field name="name">library.book.form</field>
    <field name="model">library.book</field>
    <field name="arch" type="xml">
      <form string="Book">
        <sheet>
          <group>
            <field name="name"/>
            <field name="author_id"/>
            <field name="isbn"/>
          </group>
        </sheet>
      </form>
    </field>
  </record>
</odoo>

The important fields are:

  • name: a label for developers, shown in the technical menu.
  • model: the model the view displays (library.book).
  • arch: the XML architecture, the part that matters.
  • inherit_id: set when the view extends another one (see Customising with View Inheritance).
  • priority: when several views of the same type exist, the lowest number wins.

The record id (view_library_book_form) becomes an external ID (library.view_library_book_form) you can reference from other files.

The main view types

The root tag of arch is the view type.

Root tag Purpose
<form> Edit or read one record
<list> A table of many records (called <tree> before Odoo 18)
<kanban> Cards, often grouped into columns
<search> Filters, group-by options and the search bar
<calendar> Records placed on days
<graph> and <pivot> Charts and cross tables
<gantt>, <map>, <activity> Planning, geography and follow-ups

Some of these (gantt and map, for example) come from Enterprise modules, while the rest are in Community.

flowchart LR
    A["Menu item"] --> B["Window action<br/>ir.actions.act_window"]
    B --> C["view_mode: list,form,kanban"]
    C --> D["Default view per type<br/>(lowest priority)"]
    D --> E["arch XML sent to the web client"]

A menu click opens an action. The action lists view modes, and the server picks the default view of each type for the model.

Actions choose the view modes

A window action binds a model to a list of view modes:

XML
<record id="action_library_book" model="ir.actions.act_window">
  <field name="name">Books</field>
  <field name="res_model">library.book</field>
  <field name="view_mode">list,form</field>
</record>

Opening it shows the list first, and clicking a row switches to the form. If you want a particular view instead of the default one, add view_id for a specific one, or use ir.actions.act_window.view records to map each mode to a view.

The server validates the architecture

When a module is installed, Odoo parses every arch, checks that each <field name="..."> exists on the model and that attributes are valid. A typo gives an error when you install or upgrade, not later in front of a user. That is why the typical development loop is: edit the XML, restart with -u your_module, reload the browser. You will see the commands in Configuration and Deployment.

A stand-in: reading an arch

Odoo's own code uses lxml to parse views. This stand-in uses the standard xml.etree.ElementTree to do the first things the framework does: find the view type from the root tag and collect the fields that the screen needs.

Python Inspect view architectures

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The second example models the next check: every field named in an arch must exist on the model.

Python Validate fields against a model

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Practical tips

  • Keep one XML file per model's views, named like views/library_book_views.xml, and list it in the manifest data key. Files are loaded in order, so views must come before menus that use their actions.
  • Name views model.name.type (library.book.form). Consistent names make debug mode searches easy.
  • Turn on developer mode (?debug=1) to see the active view's XML, its external ID and an Edit View option on any screen.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where is the XML of an Odoo form view stored at runtime?

    Views are database records of ir.ui.view. The XML you write in a module is loaded into the arch field, which is why other modules can modify it.
  2. 2. Which root tag describes a table of many records?

    List views show rows. Odoo 18 renamed the root tag from tree to list.
  3. 3. What decides which view types open when you click a menu item?

    The action's view_mode lists the types (for example list,form). The server then picks the default view of each type for the model.
  4. 4. When is a typo in a field name inside an arch usually reported?

    Odoo validates the architecture against the model when loading it, so mistakes surface during install or upgrade.

Summary

  • A view is an ir.ui.view record whose arch field holds XML.
  • The root tag is the view type: form, list, kanban, search, calendar, graph, pivot and more.
  • Window actions pick the view modes; the lowest priority view of each type is the default.
  • Odoo validates fields in the arch against the model when loading a module.
  • Developer mode shows you the view behind any screen.

Next: Form Views, Groups and Widgets