-
Book Overview & Buying
-
Table Of Contents
Odoo 10 Development Essentials
By :
From the previous section, we already got a taste of what it is like to use the ORM API. Next we will look at what more we can do with it.
During our journey, the several methods we encountered used API decorators like @api.multi. These are important for the server to know how to handle the method. Let's recap the ones available and when they should be used.
The @api.multi decorator is used to handle recordsets with the new API and is the most frequently used. Here self is a recordset, and the method will usually include a for loop to iterate it.
In some cases, the method is written to expect a singleton: a recordset containing no more than one record. The @api.one decorator was deprecated as of 9.0 and should be avoided. Instead we should still use @api.multi and add to the method code a line with self.ensure_one(), to ensure it is a singleton.
As mentioned, the @api.one decorator is deprecated but is still supported. For completeness, it might be worth...