Odoo Help

Welcome!

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.

1

Difference between @api.one and @api.multi in @api odoo (openerp).

By
Jay Patel (jpa)
on 11/19/14, 12:12 AM 7,049 views

Hello,

    Seriously I can't find the decent point to say both are different to each other. and give me one example to which saturation to use @api.one and @api.multi ?

    One more thinks i would like to ask even if I define a method, that case which one is either @api.one or @api.multi preferable to specify above the method. thank you

5

Yenthe

--Yenthe--
6676
| 7 7 8
Turnhout, Belgium
--Yenthe--

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

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

Yenthe
On 11/19/14, 1:56 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

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 {}

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

You are spot on. api.multi is a single function call for multiple ids. Api.one means a function call for each id, which automatically iterates when multiple id's are sent.

Ludo - Neobis
on 11/19/14, 3:12 AM
0

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2983
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 6/22/16, 1:59 PM

it is very easy...


you our should never use api.one !

but always api.multi !

and if you want to work only with one record ... Use ensure_one() function ... with api.multi

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

3 follower(s)

Stats

Asked: 11/19/14, 12:12 AM
Seen: 7049 times
Last updated: 7/1/16, 6:50 AM