This question has been flagged
2 Replies
6412 Views

Hello,

I am trying to deduct salary for unpaid leaves based on number of days of month. 

In hr.payslip following line is added.

day =  datetime.strptime(date_to,"%Y-%m-%d").day

res['value'].update({
'day': day,
})

'day' give me last day of month. For salary rule I have try:

result=(contract.wage/payslip.day)*worked_days.Unpaid.number_of_days

But Following error occur:

res['value'].update({
TypeError: list indices must be integers, not str 

I understand error, also try for integer list but nothing will happen.Any suggestion

For above I refer following link:

https://www.odoo.com/forum/help-1/question/unpaid-leaves-deduction-not-working-16131

and also I want to define organisation holiday. For organisation holiday salary not deduct for that I want add salary rule.

Avatar
Discard
Best Answer

The calculations you defined here are entirely wrong. How can u make sure your to-date in payslip is the last day of the month. One more thing to be checked here is if you put the salary for two months then which day you gonna take. 

In case of a payslip period in a single month.

Total days in a month can be calculated using this formula.

import calendar
day_from = fields.Date.from_string(from_date) #TO date object
calendar.monthrange(day_from.year, day_from.month)[1] # will be 31 | 30, For FEB 28|29
Payslip period for more than a month.
for this case I can suggest you two logics. 
1. You can predefine the the total days like 30 | 31.
2. result will be the sum of total of all months.
eg: result = result + (contract.wage/payslip.day of nth month)*worked_days.Unpaid.number_of_days
To do that, you can either split the Worked day lines according to the months or you can hard code in salary rules.
Avatar
Discard
Author

I want payslip only for one month not for more than month that's the reason I am consider to_date as a last date of month. But the problem is that when adding result=(contract.wage/payslip.day)*worked_days.Unpaid.number_of_days into the salary rule. gives me error "float division by zero" means payslip.day not contain 30 | 31. I dont understand why this happen. I am also tried your suggestion for one month payslip but not work.

Your payslip.day is zero, that's why. Properly update value to payslip.day

I don't know how you are updating payslip.day, but I can suggest you keep that as a computed field. I think you are updating the value wrongly.

Author

Firstly i inherit hr.payslip with get_worked_day_lines method in that I have try this code

day_from = fields.Date.from_string(date_from)

day = calendar.monthrange(day_from.year, day_from.month)[1]

res1.append(day)

return res1[0]

I think I am inheriting wrong method that's the reason payslip.day

Author

I think I am inheriting wrong method that's the reason payslip.day contain zero.

okay, make your field as computed and in the computed function, do the tweak

Author

Thanks @Hilar AK for your time and suggestion. My problem is solved.

Best Answer

Hi,

Please check whether this helps,

1. Deduct Employee Salary When Taking Leaves In Odoo Payroll

2. How To Set Public Holidays/Global Leaves In Odoo

Thanks

Avatar
Discard
Author

Thanks @Niyas Paphy for your time and suggestion.links given by you also helpfull.