跳至內容
選單
此問題已被標幟
2 回覆
2576 瀏覽次數

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'.




頭像
捨棄
作者 最佳答案

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​
頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
6月 22
4505
2
6月 18
6066
2
11月 16
13685
2
2月 24
12541
0
10月 23
2890