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".
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
- id - unique id is require to connect to action
- model - required scheme of ir.ui.view can be checked from the database
- field - required three attributes
- name="name" - here "name" is the title of form/tree view
- name="model" - here model will be the name of model that will be mapped to our view (tree/form)
- 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.