Greetings Everyone,
In this blog-post, you will learn how to create a Form View in an Odoo 8 module.
What is Form View in Odoo?
- Form views are used to display the data from a single record.
- Forms are used to create and edit single records.
- The root element of a form view is
<form>.
- It consists of regular HTML with additional structural and semantic components.
- It is composed of high-level structure elements (groups, notebooks) and interactive elements (buttons and fields)
Example of a Form View :-
Earlier in my previous blog-post, I had created a Model to collect student’s information. Now I will create a Form View for the student model which will give it a User Interface from where entry can be created or edited.
Code for creating a Form View
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<openerp> <data> <!-- Form View for Student --> <record id="student_form_view" model="ir.ui.view"> <field name="name">student.form.view</field> <field name="model">student.student</field> <field name="arch" type="xml"> <form> <sheet> <field name="image" widget="image" class="oe_left oe_avatar"/> <h2><field name="name" placeholder="Name"/></h2> <group string="Student Information"> <group> <field name="email"/> <field name="contact"/> <field name="dob"/> <field name="course_id"/> </group> <group> <field name="registration_date"/> <field name="gender"/> <field name="is_physically_disabled"/> <field name="hobby_ids" widget="many2many_tags"></field> </group> </group> <notebook> <page string="Qualification"> <field name="qualification_ids"> <form> <group> <field naame="course_id"/> <field name="year_cleared"/> <field name="grade"/> </group> </form> <tree> <field name="course_id"/> <field name="year_cleared"/> <field name="grade"/> </tree> </field> </page> </notebook> </sheet> </form> </field> </record> </data> </openerp> |
Steps for creating Form View in Odoo
- All views are stored in the database, in the
ir.model.view
model. To add a view in a module, we declare a<record>
element describing the view in an XML file that will be loaded into the database when the module is installed. - The root element of a Form View is <form>
- <sheet> tag is used to give the form a responsive layout
- <group> is used to define column layouts in forms. By default, groups define 2 columns and most direct children of groups take a single column.
- <field> direct children of groups display a label by default, and the label and the field itself have a colspan of 1 each.
- <notebook> defines a tabbed section. Each tab is defined through a
page
child element.
SnapShot of Eclipse IDE:-


Hope you learnt how to create a Form View in Odoo module, your reviews/comments/suggestions/doubts are most welcomed, please comment in the section below, and subscribe to the newsletter to receive timely future updates of this blog.
Now next, Learn how to create a Tree View in Odoo 8.
Thank You
2 thoughts on “Learn – How to create a Form View in Odoo 8”
Mauricioo
(February 28, 2018 - 7:05 pm)Hi man, i have a question about how create a form in odoo with two models, it is possible ang how did it ?
Burhan Vakharia
(February 28, 2018 - 7:16 pm)Hello Mauricioo, You cannot create a form view in Odoo with two models. It means you cannot add fields from two different models in one form view. You cannot do this unless they have a ‘_inherits’ relationship like res.partner and res.users.