Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9046 Lượt xem

Hello Everyone, I wanted to some work in the background without blocking the UI in Odoo.

I have to send some data over API but if somehow network is not connected or the connection is a timeout, I wanted that work should pass to some function which will keep running in the background but without blocking the UI. 

If there are the number of tasks which are not able to pass over API all those work should be running in the background for some period of time like 1 hour. How can I make some tasks working in the background without blocking UI to do some other works?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can create new envirohnment and call your function with new env, it will not affect any thing front end.

Below is the code for create new Env-

new_env = odoo.api.Environment(self.cr, self.uid, self.context)
Define your object with new Env like below-
partner_obj = new_env['res.partner']
Then you can call any partner_object function which will not block your UI.
You can see many examples in odoo base addons.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can use threading technique. It will run the process in background and UI will not be blocked.

eg:-

import threading

def fn(self):

threaded_calculation = threading.Thread(target=YOUR_FN_NAME)
threaded_calculation.start()

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 12 22
3614
2
thg 4 20
4528
1
thg 4 20
3472
2
thg 6 19
5579
0
thg 6 21
3331