Odoo Help


leaves and salary calculation.

on 6/14/13, 4:52 AM 10,237 views

hi. Any one please tell me how to reduce the salary of an employee who take leave.

eg: salary=5000

he/she take one leave in a month , then reduce rs.100 from his salary. Ie then remaining salary is 4900.How to configure this in openerp v7.0.

i assigned a salary rule (Deduction Towards Leave Availed) to salary structure.

there is a field for adding python code in this rule. how to implement my need through python code. please help..

On 6/16/13, 4:28 AM


You need to add salary rule to salary structure to deduct (add python code)


then you can deduct from salary depending on number of Unpaid leave taken by employee

and you need to put the condition for this rule (Not Always True )

result=worked_days.Unpaid and worked_days.Unpaid.number_of_days or False


I have 4 types of leaves(Sick,legal,casual,unpaid). how can i generalize this? Did i want to create 4 separate salary rule?

on 6/17/13, 2:07 AM

@Remya you can use unpaid for unpaid leave and put salary rule for it (you can put more than one salary rule as you want)

on 6/17/13, 3:34 AM

@charlesaj first you should installed holiday model and have leave (named unpaid )

on 6/17/13, 3:42 AM

hi.. that error conditions occured at i calculate the payslip for employee who did n't take leave. The error is like. Error!

Wrong python code defined for salary rule Deduction Towards Leave Availed (DLA).

on 6/17/13, 4:33 AM

OK , But when Employee have unpaid leave will work successfully ,you just need condition to the salary rule (Not Always True ) (the condition will check if employee have leave then apply salary rule else don't do anything ) -I have edit my answer vote up and select as correct answer if solved your problem -

on 6/17/13, 4:46 AM

yes employess with unpaid leave run succesfully..

on 6/17/13, 5:15 AM

then add condition I have Edit my answer

on 6/17/13, 5:18 AM

ok now the problem is ok.. for employees without have leaves.. inorder to calculate the salary deduction(for leave days) from it i use "result= (contract.wage)*worked_days.Unpaid and worked_days.Unpaid.number_of_days or False". This will return the error. any way to implement it..

on 6/17/13, 7:22 AM

sorry i use result= (contract.wage/30)*worked_days.Unpaid and worked_days.Unpaid.number_of_days or False

on 6/17/13, 7:24 AM

Same thing can be done for Half Day leaves also. You have to create leave type as half day and use the same code (replace unpaid with half day) and divide by 2

Raminder Pal Singh
on 6/17/13, 7:46 AM

@charlesraj use the code in my answer please and tell me what the problem you need 1- salary rule 2- condition for this salary rule

on 6/17/13, 8:02 AM

sir i need to calculate the deduction for the leave days..ie. Now for one unpaid leave 1 is reduced from the net salary . But i want to deduce the total salary of particular leave day from the net salary..

on 6/17/13, 8:10 AM

condition for the salary rule.. Deduct the salary(days which employee take leaves) from the net salary .

on 6/17/13, 8:13 AM

do not understand , the deduction should be from Basic salary my dear , other deduction you can put it as input (by value or do code for it) hope that help you

on 6/17/13, 8:20 AM

i want to put code in the salary rule. now i applied your code. it make the deduction of salary for the number of leave taken. ie: what i say is If He/She take one leave ONE will be deduced from the net salary..

on 6/17/13, 8:41 AM

Thank sir it work for me....i will add like this....result=-(worked_days.Unpaid and worked_days.Unpaid.number_of_days*(contract.wage/30)) or False ...

on 6/17/13, 8:52 AM

I added same rule and condition but it will not affecting on calculation of payslip amounts and so on....even that rule is not appearing on Payslip form view after clicked on compute sheet

on 7/30/13, 10:39 AM
On 10/8/15, 5:31 AM

Half pay leave this worked 

result=(worked_days.Halfpaidsickleave and worked_days.Halfpaidsickleave.number_of_days*(contract.wage/30)/2) or False

On 5/21/14, 3:22 AM


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/14/13, 4:52 AM
Seen: 10237 times
Last updated: 10/8/15, 6:03 AM