Using Odoo Studio to create a new Model

It’s easy to create a new Model (database table) by using Odoo Studio, and this can be a good way to learn a little about the Odoo architecture.

Start by clicking on the Odoo Studio icon in the top right hand corner

Now click on “Edit Menu”

The “Edit Menu” menu dialog is displayed. Scroll to the bottom and click on “New Menu”

The “Create a new Menu” dialog is displayed:

Enter a name for the menu and the Model (database table)

Of course, this can either be an existing Model or one that we want to create. In this case we want to create a Model: an additional prompt will be displayed to confirm this.

Then click on the “Confirm” button and a new menu will be added. Usually it won’t be where you want it, so simply “drag and drop” to another place. In this case we’ll move it to the Orders tab, underneath Customers.

Click on “Confirm” again” and now we can see the new menu option:

Click on the menu option and a very basic “List View” is displayed:

The List View shows only the Name field.

The “New Fields” section allows you to add more fields to the Model

Existing Fields

This shows the standard fields that were created automatically:

  • Created by |create_uid | many2one
  • Created on | create_date | datetime
  • Display Name | ​display_name | char
  • ​ID | id | integer
  • Last Modified on | __last_update | datetime
  • Last Updated by | write_uid | many2one
  • ​Last Updated on | write_date | datetime

Name

The “Name” field is not shown because it is already in the List View

  • Name | x_name| char (custom field)

The “Name” field is important in Odoo. This is what is displayed in lists and at the top of the “Form View”. In many cases the name should be entered by a user (e.g. product, customer, and this example of a Business Type), but there are other possibilities:

  • Name will be a sequence number. This can set up quite easily.
  • Name could be automatically set based on other fields.
    • Because Odoo defines the x_name field as “custom” it’s possible to set it as computed.

Odoo will make the Name field mandatory, and whilst you can change this (through Studio) it’s not recommended because if it’s blank any lists (e.g. to select a record from this Model) will not be usable.

It’s also NOT a good idea to delete the Name field (for the same reason), so try to use one of the above options to set a value.

Note: programmers can change the behaviour of Odoo so that a different field name is displayed in lists.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s