Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4531 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
2491
2
ก.ค. 25
7934
2
ก.ค. 25
4368
2
ก.ค. 25
4083
2
มิ.ย. 25
2681