Methods for writing model data

The ORM provides three methods for the three basic write operations:

  • <Model>.create(values) creates a new record on the model. Returns the created record.
  • <Recordset>.write(values) updates field values on the recordset. Returns nothing.
  • <Recordset>.unlink() deletes the records from the database. Returns nothing.

The values argument is a dictionary, mapping field names to values to write.

In some cases, we need to extend these methods to add some business logic to be triggered whenever these actions are executed. By placing our logic in the appropriate section of the custom method, we can have the code run before or after the main operations are executed.

Using the TodoTask model as an example, we can make ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.