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

accessing one record with two counters at once

By
Alexander Soare
on 8/18/16, 4:16 AM 139 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?


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

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

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: 8/18/16, 4:16 AM
Seen: 139 times
Last updated: 8/18/16, 4:27 AM