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

I have a date field in a custom helpdesk ticket for a date, let's call that x_studio_warranty_end


In an integer field (call it x_studio_days_remaining_on_warranty) I want to compute how many days from TODAY that is. I.e. if the warranty end is '1/1/2024', I want my field to show '30'.




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

I ended up figuring it out after looking at many different places, maybe not the cleanest... 

for record in self:
if record.x_studio_warranty_end:​
​dt = datetime.datetime.now()
​dwarr = record.x_studio_warranty_end
​dwarrdt = datetime.datetime.combine(dwarr, datetime.datetime.min.time())
record['x_studio_days_remaining_on_warranty'] = (dwarrdt - dt).days​
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can also use Studio to change the widget of your date field to "Remaining Days". 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 6 22
4459
2
thg 6 18
6023
2
thg 11 16
13607
2
thg 2 24
12508
0
thg 10 23
2851