I want to set a flag when a user enters a datetime which is either before 10 minutes from now or after 10 minutes from now.
I have tried many possibilities but I am not getting the proper result. Can anyone help me please.
Error message : ValueError: time data '' does not match format '%Y-%m-%d %H:%M:%S'
py file :
@api.multi
def write(self, values):
check_out = values.get('check_out', '')
log_in = values.get('log_in', '')
log_out = values.get('log_out', '')
check_in = values.get('check_in', '')
import datetime
now = datetime.datetime.now()
d = now.replace(microsecond=0)
my_login_time = datetime.datetime.strptime(log_in, '%Y-%m-%d %H:%M:%S')
my_logout_time = datetime.datetime.strptime(log_out, '%Y-%m-%d %H:%M:%S')
start_time = d - datetime.timedelta(minutes=10)
end_time = d + datetime.timedelta(minutes=10)
if check_in:
if my_login_time > end_time or my_login_time < start_time:
self.set_flag = True
if check_out:
if my_logout_time > end_time or my_logout_time < start_time:
self.set_flag = True
res = super(AgendaLine, self).write(values)
return res
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
3453
Lượt xem
Hello @Sumit,
Make sure that login_in field in datetime.datetime.strptime(log_in, '%Y-%m-%d %H:%M:%S') would be in the same format as you were take in strptime parameter('%Y-%m-%d %H:%M:%S'). And also make sure that login_in field should in string format but not in datetime format.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 1 21
|
2411 | ||
Leave Summary: Number of Days
Đã xử lý
|
|
1
thg 10 17
|
3109 | |
|
3
thg 5 24
|
10882 | ||
|
2
thg 5 20
|
4823 | ||
|
2
thg 5 18
|
5267 |