Odoo Help

6

Yenthe

--Yenthe--
9439
| 8 8 8
Belgium
--Yenthe--

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

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

Yenthe
On 5/6/16, 11:04 AM

Hi MouBou,

self.ensure_one is made to ensure that only one record is being passed on. It checks that the current record is a singleton (so just one record, not multiple records). If self would contain multiple records the system would throw up an error. An example case to check you just have one record:

@api.multi
def some_fuction(self):
    # This will make sure we have on record, not multiple records.
self.ensure_one()

When you would run this code with a selection of records (for example selecting multiple records from a treeview) the self.ensure_one() would check this and throw up an error.

A general rule of thumb is to only use self.ensure_one when you are sure / want to be sure you only have one record, not multiple. In cases of you using multiple records in one action you should use @api.multi without self.ensure_one()
Have a look at the ORM documentation: https://www.odoo.com/documentation/8.0/reference/orm.html

Yenthe

0

This function will be called !!!




Thanks !!
Shameem Babu @ iWesabe

0
Subhanullah
On 12/5/17, 12:03 PM

To reply your second question,

You can use @api.one, but since @api.one put returned value in a list and it is not always supported by the web client, therefore most of the developers uses@api.multi with self.ensureone().

Refer to this link for more details,

http://odoo-new-api-guide-line.readthedocs.io/en/latest/decorator.html

0
Thang Duong Bao
On 8/30/17, 10:49 PM

@Yenthe: so why not use @api.one only, example:

@api.one
def some_fuction(self):
     # ...

We can't call wizards from @api.one.

GLOBAL CREATIVE CONCEPTS TECH CO LTD (iWesabe)
on 3/8/18, 12:13 AM

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

Question tools

2 follower(s)

Stats

Asked: 5/6/16, 10:56 AM
Seen: 6039 times
Last updated: 3/21/18, 4:44 AM