Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
5071 Visualizzazioni

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?

Avatar
Abbandona

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,

Post correlati Risposte Visualizzazioni Attività
0
mar 22
2700
0
feb 21
2266
2
lug 25
3739
1
lug 25
2939
0
dic 24
1633