Odoo Help


accessing one record with two counters at once

Alexander Soare
on 8/18/16, 4:16 AM 589 views

odoo 9.0 


I have overwritten the create method for res.partner. Part of my custom functionality writes to a record of a custom model called x_vehicle (there is a many2many field in res.partner pointing to x_vehicle). The situation is such that I need this write to be an isolated transaction because I don't want it to be rolled back if an exception is thrown downstream. To solve this I open a new counter to write to this field as so:

# the 'id' parameter below is the database id of the x_vehicle object in the many2many
# field of the res.partner being created
with openerp.api.Environment.manage():     
    with openerp.registry(self.env.cr.dbname).cursor() as new_cr:         
        new_env = api.Environment(new_cr, self.env.uid, self.env.context)
  self.env['x_vehicle'].with_env(new_env).browse([id]).update({"x_is_car": True})          
# You don't need close your cr because is closed when finish "with"
# You don't need clear caches because is cleared when finish "with" 


Odoo gets stuck with loading bar for an indefinite period of time. No output in the logs on debug level.


  • Trying to write to some other model with the same method works.

  • Trying to write to x_vehicle model but to any other record works. It seems that odoo doesn't like that in the above case I'm trying to write the the record which is supposed to be linked to the current res.partner being created. Perhaps the problem happens because I'm trying to access the record with the counter from self.env and the new_cr at the same time?

Thoughts and ideas?


And if your try something like...:

with self.pool.cursor() as newcr:

newcr.execute('''UPDATE x_vehicle SET x_is_car=TRUE WHERE id=%s;''', (id,))

Jérémy Kersten (jke)
on 8/18/16, 4:36 AM

@Jérémy the problem as described in the OP remains the same. Also as in the diagnosis I'm still able to replace id with any other record of x_vehicle and it works.

Alexander Soare
on 8/18/16, 4:58 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

1 follower(s)


Asked: 8/18/16, 4:16 AM
Seen: 589 times
Last updated: 8/18/16, 4:27 AM