Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
2550 Zobrazení

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




Avatar
Zrušit
Autor Nejlepší odpověď

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​
Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
čvn 22
4478
2
čvn 18
6041
2
lis 16
13641
2
úno 24
12526
0
říj 23
2873