How it works...

The first step adds a more user-friendly title to the model's definition. This is not mandatory, but can be used by some add-ons. For instance, it is used by the tracking feature in the mail add-on module for the notification text when a new record is created. For more details, refer to Chapter 23, Managing Emails.

By default, Odoo orders the records using the internal id value. However, this can be changed so that we can use the fields of our choice by providing an _order attribute with a string containing a comma-separated list of field names. A field name can be followed by the desc keyword to sort it in descending order.

Only fields stored in the database can be used. Non-stored computed fields can't be used to sort records.

The syntax for the _order string is similar to SQL ORDER BY clauses, although it's stripped down. For instance, special clauses, such as NULLS FIRST, are not allowed.

Model records use a representation when they are referenced from other records. For example, a user_id field with the value 1 represents the Administrator user. When displayed in a form view, Odoo will display the username, rather than the database ID. By default, the name field is used. In fact, this is the default value for the _rec_name attribute, which is why it's convenient to have a name field in our models.

If no name field exists in the model, a representation is generated with the model and record identifiers, similar to (library.book, 1).

Since we have added a new field, short_name, to the model, the Odoo ORM will add a new column in the database table, but it won't display this field in the view. To do this, we need to add this field in the form view. In step 4, we added the short_name in the form view.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset