Odoo Help


Are cr and uid (cursor and user id) necessary with every method call in version 8?

Atte Isopuro
on 8/8/14, 7:34 AM 11,893 views

I had heard somewhere that one of the features planned for the orm in v8 was that you wouldn't need to pass cursor and user id with every call to a model's method, i.e:

self.pool.get('some.model').browse(cr, uid, id_list)  # Old way

self.pool.get('some.model').browse(id_list)  # New way.

Assuming that this is still going to be implemented (maybe it has been already?) I would like to make sure it works in all contexts. Specifically, I am making custom http-endpoints as part of a module. At least in the v7 way of doing things, I find models from request.registry instead of self.pool. If I call model methods in this way:


will it work?

I am currently developing on a pull from the master branch of Odoo from 2014-08-05, and calling browse() with just a list of id's throws a TypeError (expects at least 3 arguments). Can I expect the new way to work in future (or am I maybe doing it wrong)?

I don't have enough Karma to comment Dhinesh's post so I'll put this here for now: If I try to use Env I get a NameError (global name 'Env' is not defined). Where can I import it from?

Atte Isopuro
on 8/8/14, 8:34 AM

All new v8 features are in [from openerp import api] or for environment use [from openerp.api import Environment] You can use it from self itself like cr, uid, context = self.env.args. For more info check addons/account/partner.py -> @api.v8 def map_tax(self, taxes):

Dhinesh - Technical Consultant, Sodexis Inc
on 8/8/14, 9:32 AM

Thank you very much: helpful and very fast.

Atte Isopuro
on 8/8/14, 9:33 AM

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 8/8/14, 7:56 AM

Yes, the traditional way has been modified in V8 with new api.

For instance, the statements::

        model = self.pool.get(MODEL)
        ids = model.search(cr, uid, DOMAIN, context=context)
        for rec in model.browse(cr, uid, ids, context=context):
            print rec.name
        model.write(cr, uid, ids, VALUES, context=context)

    may also be written as::

        env = Env(cr, uid, context)         # cr, uid, context wrapped in env
        recs = env[MODEL]                   # retrieve an instance of MODEL
        recs = recs.search(DOMAIN)          # search returns a recordset
        for rec in recs:                    # iterate over the records
            print rec.name
        recs.write(VALUES)                  # update all records in recs

    Methods written in the "traditional" style are automatically decorated,
    following some heuristics based on parameter names.

Good and clear answer!

21south, Ludo - 21South
on 8/8/14, 9:51 AM

Thanks @ Dhinesh Your answer help full me. +1

Ankit H Gandhi(AHG)
on 3/31/16, 8:08 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.


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)


Asked: 8/8/14, 7:34 AM
Seen: 11893 times
Last updated: 3/16/15, 8:10 AM