How to create a form view in Odoo?

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:

marks

The Marks model has associated a form view:

formview

  • 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.

action

  • 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:
menus

An example of the result after this tutorial:

demo.png

What am I missing here? Let me know in the comments and I’ll add it in 🙂

3 thoughts on “How to create a form view in Odoo?

  1. truc@machin.fr says:

    You shouldn’t make screenshots of your code but add it into a balise with syntax coloration. With this procedure a random user can still copy the code et paste it into a test base and haven’t to read the photo and then copy the code.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.