How it works...

Normally, Odoo will create a new table for the model you are defining by using the field definitions for the columns. Actually, this is because in the BaseModel class, the _auto attribute defaults to True. In step 1, by positioning this class attribute to False, we tell Odoo that we will manage this by ourselves.

In step 2, we define some fields that will be used by Odoo to generate a table. We take care to flag them as readonly=True, so that the Views do not enable modifications that you will not be able to save, since PostgreSQL Views are read-only.

Step 3 defines the init() method. This method normally does nothing; it is called after _auto_init() (which is responsible for the table creation when _auto = True, but does nothing otherwise), and we use it to create a new SQL view (or to update the existing view in the case of a module upgrade). The view creation query must create a view with column names that match the field names of the Model.

It is a common mistake, in this case, to forget to rename the columns in the view definition query, and this will cause an error message when Odoo cannot find the column.

Note that we also need to provide an Integer column called ID that contains unique values.

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

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