Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
Hi all ,
Anybody can explain ,when we can use these api methods in odoo ,please explain an example with some scenarios
Thanks in advance....
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
An example of @api.decorator:
return x # a RecordSet
An example of @api.model:
An example of @api.depends:
You can read more about all the decorators and methods here: http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html
About This Community
This platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 1/23/15, 3:38 AM|
|Seen: 638 times|
|Last updated: 3/16/15, 8:10 AM|