Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4986 Widoki

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?

Awatar
Odrzuć

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,

Powiązane posty Odpowiedzi Widoki Czynność
0
mar 22
2619
0
lut 21
2205
2
lip 25
3570
1
lip 25
2717
0
gru 24
1455