This question has been flagged

I find the documentation on this a little vague..

https://www.odoo.com/documentation/11.0/reference/orm.html#module-odoo.api

I'm not really sure which to use, as both works as expected in my project.

Can someone please explain the difference to me with simple words? A simplified example would be great.


Avatar
Discard
Best Answer

Hi Alf,

as a rule of thumb you can say the following (with a few exceptions): The @api.multi call is used for functions where you want to do some operation on one or multiple records. An example here can be setting a field on multiple records:

@api.multi
def update_sale_order_dates(self):
    for order in self:
order.your_field = 'new value'

The @api.model decorator is used for framework related usecases.
Look at @api.model as the decorator that you need to do something on the model level itself, not just some record(s). Schedulers for example use the @api.model decorator. You can use the @api.model decorator for model structures, helper methods and so on.


I hope this helps you a bit. You might also want to look through the official Odoo code as there are loads of examples there! 
See https://github.com/odoo/odoo/search?q=%40api.model&unscoped_q=%40api.model and https://github.com/odoo/odoo/search?q=%40api.multi&unscoped_q=%40api.multi - usually the best way to learn is to look at the source code.

Regards,
Yenthe

Avatar
Discard