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

I want to create timer in odoo view which support run/pause (using button ) something like Soccer match time , min:sec format

I tried below code but it generated an error

api.one
def timer_th(self):
    timer_thread = Thread(target=self.timer)    timer_thread.start()

def timer(self):
    while self.current_time <= self.duration:
        time.sleep(1)        self.current_time += 1

it gave me AttributeError: environments error
but when I used the code without thread it works but gui wasn't responsive

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

Hi there, I think your code might need some adjusting.

Try the below code:

import threading

def timer_th(self):
    timer_thread = threading.Thread(
​target=self.timer,
​args = ()
​)
    timer_thread.start()

def timer(self):
​with self.pool.cursor() as new_cr:
​self = self.with_env(self.env(cr=new_cr))
    ​while self.current_time         ​time.sleep(1)
        ​self.current_time += 1
​new_cr.commit()

I use something like that and it works.

Good Luck



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

is this error is solved or not. I also want to set the timer for 45min.After 45mins i want to show pop up message to enter the work. Can you help  me.... Thank you.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 24
2759
6
thg 10 15
5509
2
thg 2 25
1256
0
thg 7 21
3413
1
thg 11 20
5062