Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


When we can use API in odoo8 and what is the use of APIs

on 1/23/15, 3:38 AM 513 views

Hi all ,

Anybody can explain ,when we can use these api methods in odoo ,please explain an example with some scenarios


Thanks in advance....



| 7 7 8
Turnhout, Belgium

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

On 1/23/15, 4:07 AM

If I am not mistaking it is very easy and clear.
The @api.one is specific for one record and can not be used for multiple records. It automaticly loops on records of of a Recordset for you. 
@api.many is for multiple records, where you can loop through it etc. It will be the current Recordset without the itiration. So any looping would need to be programmed by yourself, for whatever you want
@api.model is basicly a converter from the old API to the new API. (Odoo V7 -> Odoo V8) Its for migrating code.
@api.depends will trigger the call to the decorated function if any of the fields specified in the decorator is altered by ORM or changed in the form..

An example of @api.one:

@api.one def _compute_name(self):
      self.name = str(random.randint(1, 1e6))

An example of @api.multi:

@api.multi def subscribe(self):
     for session in self.session_ids:
         session.attendee_ids |= self.attendee_ids
     return {}

An example of @api.decorator:

def afun(self):
    return x # a RecordSet

An example of @api.model:

def afun(self):

An example of @api.depends:

@api.depends('name', 'an_other_field')
def afun(self):

You can read more about all the decorators and methods here: http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html

Thanks Yenthe.........

on 1/23/15, 4:35 AM

Thank you so much Yenthe

Ankit H Gandhi(AHG)
on 1/23/15, 5:06 AM

No problem guys! Best of luck. Please accept/upvote my answer if it has helped you :)

on 1/23/15, 5:22 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 1/23/15, 3:38 AM
Seen: 513 times
Last updated: 3/16/15, 8:10 AM