Odoo Help


4 Answers

Kazim Mirza | Founder at TechUltra Solutions India

--Kazim Mirza | Founder at TechUltra Solutions --
| 3 3 7
Ahmedabad, India
--Kazim Mirza | Founder at TechUltra Solutions --
Kazim Mirza | Founder at TechUltra Solutions India
7/15/16, 1:32 AM

Hello Prince.
Below is the example.

import thread
from openerp.http import request
def button_method(self): #this is button method from wizard call
    #you need to set kwargs for db and uid
    kwargs = {'uid': request.uid, 'db': request.db}
    thread.start_new_thread(self.theard_method, (kwargs, arg1, args2, args_n)
    return {'type': 'ir.actions.act_window_close'}
def thread_method(self, kwargs, arg1, arg2, arg_n):    
new_cr = sql_db.db_connect(kwargs.get('db')).cursor()
with Environment.manage():
#you need to define environment as you can't use the self.env['']
env = Environment(new_cr, kwargs.get('uid'), {})
partner_obj = env['res.partner'] #example to initiate the obj

Prince Caspion United States
7/15/16, 3:02 AM

@kazim, thanks for reply but what is kwargs, args1 etc? it does not working from my side.

Kazim Mirza | Founder at TechUltra Solutions India
7/15/16, 3:09 AM

Kwargs is used to get the uid, db as you will need it in second method .

The thread will make the connection connection lost from the button method so it will need to declare the kwargs with db, uid

arg1, arg2 etc will be needed if you want to have the argument on the thread method. if you dont want any argument then you should not declare it.

Hope this helps

Dilip Dabhi India
7/15/16, 9:44 AM

when you click on button then you have to call another method, and code define in current method cut that code and past it into method of thread.

import threading

def thread_method(self):

    #Code of method

    return True

****************suppose below method is which, when you click on button**********************


def test_thread(self):

    # if you have created code here then move that code from here and past it in thread_method declare above

    thread_var = threading.Thread(target=self.thread_method)


    return True

Ask a Question
Keep Informed
2 follower(s)
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