API in Odoo
1.@api.returns
It
will return a RecordSet of specified model based on original returned
value:
@api.returns('res.partner')
def
afun(self):
.
.
.
return
x # a RecordSet
2.@api.one
The
decorated method automatically loops on records (i.e, for each record
in recordset it calls the method), and makes
a list with the results.
self
is redefined as current record:
@api.one
def
afun(self):
self.name='todo'
3.@api.multi
The
method typically defines an operation on records. Such a method:
Self
will be the current RecordSet without iteration.
@api.multi
def
afun(self):
len(self)
4.@api.model
This
decorator will convert old API calls to decorated function to new API
signature.
@api.model
def
afun(self):
pass
5.@api.constrains
This
decorator will ensure that decorated function will be called on
create, write, unlink operation. If a constraint is met the function
should raise a
openerp.exceptions.Warning
with appropriate message.
6.@api.depends
This
decorator 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:
@api.depends('name',
'an_other_field')
def
afun(self):
pass
-
7.@api.onchange
This
decorator will trigger the call to the decorated function if any of
the fields specified in the decorator is changed in the form:
@api.onchange('fieldx')
def
do_stuff(self):
if
self.fieldx == x:
self.fieldy
= 'toto'
In
previous sample self
corresponds to the record currently edited on the form. When in
on_change context all work is done in the cache. So you can alter
RecordSet inside your function without being worried about altering
database. That’s the main difference with @api.depends
At
function return, differences between the cache and the RecordSet will
be returned to the form.
-
8.@api.noguess
This
decorator prevent new API decorators to alter the output of a method
Source : http://zbeanztech.com/blog/method-decorators-odoo-8
http://odoo-new-api-guide-line.readthedocs.io/en/latest/decorator.html
http://odoo-new-api-guide-line.readthedocs.io/en/latest/decorator.html
0 comments:
Post a Comment