Skip to Content
Menu
This question has been flagged
2827 Views

odoo 9.0 

Setup:

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})          
        new_env.cr.commit()
# 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" 


Problem:

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

Diagnosis:

  • 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?


Avatar
Discard

Hello,

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,))

Author

@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.

Related Posts Replies Views Activity
0
Aug 22
1421
0
Mar 15
2431
2
Mar 15
3935
2
Jun 22
1739
1
Aug 20
7101