Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4413 Tampilan

I want to get current day of the week and compare it with selection field value.Any idea?

Avatar
Buang
Jawaban Terbai

To get current day :
current_day = datetime.today().strftime('%A') # 'Wednesday'
and for comparing the selection field see my below code.

for cal in attendance.employee_id.resource_calendar_id.attendance_ids.filtered(lambda line: dict(line._fields['dayofweek'].selection).get(line.dayofweek) == current_day and line.day_period == 'morning'):

Here,
'line' is the object like self
'dayofweek' is the selection field.
like this you can compare your selection field key with other variable.

Avatar
Buang
Jawaban Terbai

You can use weekday() of datetime.date class function.

The weekday() of datetime.date class function is used to return the integer value corresponding to the specified day of the week.

0Monday
1Tuesday
2Wednesday
3Thursday
4Friday
5Saturday
6Sunday



Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Jul 25
2905
2
Jun 25
1780
0
Mei 25
14
2
Jan 25
3338
1
Des 24
6903