Creating Views
Views define the way the records of a model are displayed. Each type of view represents a mode of visualization
Views can either be requested generically via their type (e.g. a list of partners) or specifically via their id. For generic requests, the view with the correct type and the lowest priority (by default priority=10) will be used (so the lowest-priority view of each type is the default view for that type).
Generic view declaration
A view is declared as a record of the model ir.ui.view. The view type is implied by the root element of the arch field:
<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>
Note :The view's content is XML.
The arch field must thus be declared as type="xml" to be parsed correctly.
Tree views
Tree views, also called list views, display records in a tabular form.
Their root element is <tree>. The simplest form of the tree view simply lists all the fields to display in the table (each field as a column):
<!-- Tree View -->
<record model="ir.ui.view" id="engineer.list">
<field name="name">Engineer list</field>
<field name="model">engineer.engineer</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="value"/>
<field name="value2"/>
</tree>
</field>
</record>
Form views
Forms are used to create and edit single records.
Their root element is <form>. They composed of high-level structure elements (groups, notebooks) and interactive elements (buttons and fields):
<form string="Idea form">
<group colspan="4">
<group colspan="2" col="2">
<separator string="General stuff" colspan="2"/>
<field name="name"/>
<field name="inventor_id"/>
</group>
<group colspan="2" col="2">
<separator string="Dates" colspan="2"/>
<field name="active"/>
<field name="invent_date" readonly="1"/>
</group>
<notebook colspan="4">
<page string="Description">
<field name="description" nolabel="1"/>
</page>
</notebook>
<field name="state"/>
</group>
</form>
<form>
<header>
<sheet>
<notebook>
<page>
Form views can also use plain HTML for more flexible layouts:
<form string="Idea Form">
<header>
<button string="Confirm" type="object" name="action_confirm"
states="draft" class="oe_highlight" />
<button string="Mark as done" type="object" name="action_done"
states="confirmed" class="oe_highlight"/>
<button string="Reset to draft" type="object" name="action_draft"
states="confirmed,done" />
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only" string="Idea Name" />
<h1><field name="name" /></h1>
</div>
<separator string="General" colspan="2" />
<group colspan="2" col="2">
<field name="description" placeholder="Idea description..." />
</group>
</sheet>
</form>
colspan, you can widen items. col to use more or less columns.
Search View
Search views customize the search field associated with the list view (and other aggregated views). Their root element is <search> and they're composed of fields defining which fields can be searched on:
If no search view exists for the model, Odoo generates one which only allows searching on the name field.
<record id="view_task_search_form" model="ir.ui.view">
<field name="name">project.task.search.form</field>
<field name="model">project.task</field>
<field name="arch" type="xml">
<search string="Tasks">
<!-- Fields to be viewed in the seacrh box to enable filter -->
<field name="name" string="Tasks"/>
<!-- Filter with conditions -->
<filter string="New" name="draft" domain="[('stage_id.sequence', '<=', 1)]"/>
<separator/> for giving spaces
<!-- Group By -->
<group expand="0" string="Group By">
<filter string="Project" name="project" context="{'group_by':'project_id'}"/>
<filter string="Assignation Month" context="{'group_by':'date_start:month'}" help="Creation Date"/>
<filter string="Company" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
Views can either be requested generically via their type (e.g. a list of partners) or specifically via their id. For generic requests, the view with the correct type and the lowest priority (by default priority=10) will be used (so the lowest-priority view of each type is the default view for that type).
Generic view declaration
A view is declared as a record of the model ir.ui.view. The view type is implied by the root element of the arch field:
<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>
Note :The view's content is XML.
The arch field must thus be declared as type="xml" to be parsed correctly.
Tree views
Tree views, also called list views, display records in a tabular form.
Their root element is <tree>. The simplest form of the tree view simply lists all the fields to display in the table (each field as a column):
<!-- Tree View -->
<record model="ir.ui.view" id="engineer.list">
<field name="name">Engineer list</field>
<field name="model">engineer.engineer</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="value"/>
<field name="value2"/>
</tree>
</field>
</record>
Form views
Forms are used to create and edit single records.
Their root element is <form>. They composed of high-level structure elements (groups, notebooks) and interactive elements (buttons and fields):
<form string="Idea form">
<group colspan="4">
<group colspan="2" col="2">
<separator string="General stuff" colspan="2"/>
<field name="name"/>
<field name="inventor_id"/>
</group>
<group colspan="2" col="2">
<separator string="Dates" colspan="2"/>
<field name="active"/>
<field name="invent_date" readonly="1"/>
</group>
<notebook colspan="4">
<page string="Description">
<field name="description" nolabel="1"/>
</page>
</notebook>
<field name="state"/>
</group>
</form>
<form>
<header>
<sheet>
<notebook>
<page>
Form views can also use plain HTML for more flexible layouts:
<form string="Idea Form">
<header>
<button string="Confirm" type="object" name="action_confirm"
states="draft" class="oe_highlight" />
<button string="Mark as done" type="object" name="action_done"
states="confirmed" class="oe_highlight"/>
<button string="Reset to draft" type="object" name="action_draft"
states="confirmed,done" />
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only" string="Idea Name" />
<h1><field name="name" /></h1>
</div>
<separator string="General" colspan="2" />
<group colspan="2" col="2">
<field name="description" placeholder="Idea description..." />
</group>
</sheet>
</form>
colspan, you can widen items. col to use more or less columns.
Search View
Search views customize the search field associated with the list view (and other aggregated views). Their root element is <search> and they're composed of fields defining which fields can be searched on:
If no search view exists for the model, Odoo generates one which only allows searching on the name field.
<record id="view_task_search_form" model="ir.ui.view">
<field name="name">project.task.search.form</field>
<field name="model">project.task</field>
<field name="arch" type="xml">
<search string="Tasks">
<!-- Fields to be viewed in the seacrh box to enable filter -->
<field name="name" string="Tasks"/>
<!-- Filter with conditions -->
<filter string="New" name="draft" domain="[('stage_id.sequence', '<=', 1)]"/>
<separator/> for giving spaces
<!-- Group By -->
<group expand="0" string="Group By">
<filter string="Project" name="project" context="{'group_by':'project_id'}"/>
<filter string="Assignation Month" context="{'group_by':'date_start:month'}" help="Creation Date"/>
<filter string="Company" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
0 comments:
Post a Comment