Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
2101 Prikazi

Hello Odooers,

i got 2 fields:

date_from and date_to with time both.

How to compute a field to be "True" if record date_from.time() and date_to.time() is between 00:00 and 07:00.

Thank you

Avatar
Opusti
Avtor Best Answer

Thanks to ChatGPT:

    def _compute_in_range(self):
for record in self:
# Get user's timezone
tz = self.env.user.tz or 'UTC'
# Convert datetime_field to user's timezone
dt = pytz.timezone(tz).localize(record.datetime_field)
start = datetime.strptime("00:00", "%H:%M").time()
end = datetime.strptime("07:30", "%H:%M").time()
new_dt = add_time_range(dt)
if new_dt.time() >= start and new_dt.time() <= end:
record.in_range = True
else:
record.in_range = False

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
2
jul. 22
2080
2
mar. 22
6674
1
jul. 22
2319
1
feb. 22
2732
1
apr. 24
1399