Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5073 Lượt xem

Hello,

As far as I know - we can count the number of days the employee was at work using this code:

for line in payslip.worked_days_line_ids:
result += line.number_of_days

But i dont know how we can count the number of days off in this month. The idea is that we will use the weekend for payroll, but at a different rate.


Do you have any ideas?

Ảnh đại diện
Huỷ bỏ

Hello Nikita,

I am not sure entirely if this would work with what you are trying to do, but to calculate the total number of days in the current month you can use the algorithm:

import datetime

current_month = datetime.date.today().month

current_year = datetime.date.today().year

next_month = current_month + 1 if current_month <= 12 else 1

days_in_current_month = datetime.date(current_year, next_month, 1) - datetime.date(current_year, current_month, 1)

print(days_in_current_month.days)

Or if you can import calendar

import calendar

cal_range = calendar.monthrange(current_year, current_month)

days_in_current_month = cal_range[1]

print(days_in_current_month)

You can then use the total days in the month - the number of days at work?

Or do you need days off that are weekdays?

Thanks,

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 22
2703
0
thg 2 21
2270
2
thg 7 25
3743
1
thg 7 25
2939
0
thg 12 24
1635