Search Here

How to create Form and Tree view in Odoo

In this article you will learn how to create views (form and tree) in Odoo. In my previous post you learned about "Action Menu" in Odoo. We also learned in very detail how to create action menu in odoo.

What are Views in Odoo

Odoo have several types of views, but there are three commonly used views. Which are "List, Form and Search View". List view also know as "Tree".

Difference Between Tree and Form View

Tree views displays list of records, while form views are used to create and edit single record. Odoo generates automatically tree and form view if we don't explicitly define views. But the good practice is that you would like to define view yourself. 

Views define how to display a record of a model (object). All views are stored in (ir.ui.view) model.



What is ir.ui.view


In Odoo there are two kinds of data that are stored, first one is "ir" (Information Repository) and the second is "res" (Resource). The Information Repository is used to store data needed by OpenERP to know how to work as an application. It may also used to define menus, windows, views, wizards, database tables, etc.

View Declaration


 By declaring a <record> element we add views in our module. And we describe this <record> element in (.xml) file. 

Following code snippet is used for creating views in Odoo.

<record model="ir.ui.view" id="view_id">
<field name="name">view.name</field>
<field name="model">object_name</field>
<field name="priority" eval="16"/>
<field name="arch" type="xml">
<!-- view content: <form>, <tree>, <graph>, ... -->
</field>
</record>
Important: Here arch field must be declared as type="xml".

In the above code we used two elements the first one is "record" and the another is "field".
  • record - required two attributes
    1. id -  unique id is require to connect to action
    2. model -  required scheme of ir.ui.view can be checked from the database 
  • field - required three attributes
    1. name="name" - here "name" is the title of form/tree view
    2. name="model" - here model will be the name of model that will be mapped to our view (tree/form)
    3. name="arch"  - view type is implied by the root element of "arch" field. The type of arch field must be declared as "xml" to be parsed correctly.

Post a Comment

0 Comments