Help

1

Count the number of days off to generate Payslip

Avatar
Nikita

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?

1 Comment
Avatar
Discard
Avatar
Jack Dane
-

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,