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.

0

Yenthe

--Yenthe--
6706
| 7 7 8
Turnhout, 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

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)

Stats

Asked: 5/6/16, 10:56 AM
Seen: 1467 times
Last updated: 5/8/16, 9:33 AM