Odoo - Open Academy - Generic view declaration ?

Zarshed Ali
Zarshed Ali
5000
| 2 1 2
Asked on 2/26/15, 11:23 PM
0
vote
4575 Views

https://www.odoo.com/documentation/8.0/howtos/backend.html#basic-views

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>
Danger 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 string="Idea list">
    <field name="name"/>
    <field name="inventor_id"/>
</tree>
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>
Exercise Customise form view using XML
Create your own form view for the Course object. Data displayed should be: the name and the description of the course.

openacademy/views/openacademy.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="course_form_view">
            <field name="name">course.form</field>
            <field name="model">openacademy.course</field>
            <field name="arch" type="xml">
                <form string="Course Form">
                    <sheet>
                        <group>
                            <field name="name"/>
                            <field name="description"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <!-- window action -->
        <!--
            The following tag is an action definition for a "window action",
Exercise Notebooks
In the Course form view, put the description field under a tab, such that it will be easier to add other tabs later, containing additional information.

Modify the Course form view as follows:

openacademy/views/openacademy.xml
                    <sheet>
                        <group>
                            <field name="name"/>
                        </group>
                        <notebook>
                            <page string="Description">
                                <field name="description"/>
                            </page>
                            <page string="About">
                                This is an example of notebooks
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
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>
Search views
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:

<search>
    <field name="name"/>
    <field name="inventor_id"/>
</search>
If no search view exists for the model, Odoo generates one which only allows searching on the name field.

Exercise Search courses
Allow searching for courses based on their title or their description.

openacademy/views/openacademy.xml
            </field>
        </record>

        <record model="ir.ui.view" id="course_search_view">
            <field name="name">course.search</field>
            <field name="model">openacademy.course</field>
            <field name="arch" type="xml">
                <search>
                    <field name="name"/>
                    <field name="description"/>
                </search>
            </field>
        </record>

        <!-- window action -->
        <!--
            The following tag is an action definition for a "window action",

Zarshed Ali
Zarshed Ali
5000
| 2 1 2
Answered on 2/26/15, 11:24 PM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 2/26/15, 11:23 PM
Seen: 4575 times
Last updated: 2/26/15, 11:24 PM