Hello everyone. In this blog-post tutorial we will learn how to create a form view in Odoo. Firstly, let’s define views. Views is the way the records of a model are displayed. Each type of view represents a mode of visualization ( a list of records, form, a graph, calendar, kanban). Here we will learn one mode ‘Form’ view.
So, here we have a model named Marks which has a Many2one field called ‘student_id’. This field represents the informations of the Students(e.g name, age, number,…) other Many2one field called ‘courses_id’ (e.g name, number), and Float fields ‘exam1’ ‘exam2’ ‘extra’ ‘average’. Marks model looks like this:
The Marks model has associated a form view:
- 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. The arch field must thus be declared as type=”xml” to be parsed correctly.
- record element is declared to describe the view in an XML file that will be loaded into the database when the module is installed.
- form is the root element of a form view.
- sheet used to give the form a responsive layout.
- group is used to define column layouts in forms. By default, groups define two columns and most direct children of groups take a single column.
Apart from this, you can have others window actions bind to the Marks model with different values for view_mode.
- id is the id identifier of the action in the table “ir.actions.act_windw”. It must be unique.
- name is the name of the action.
- res_model is the name of the object on which the action operates.
- view_type is set to form when the action must open a new form view
- view_model is only considered if the view_type is form. The four possibilities are “form,tree” “tree,form” “form” and “tree”
And this window action is bind to a menu item to open the Marks model view:
An example of the result after this tutorial:
What am I missing here? Let me know in the comments and I’ll add it in 🙂