# Hours based salary for employee

By
inian
on 6/6/16, 3:37 AM 1,075 views

How to calculate hours based salary for employee?

kirubanidhi
On 6/9/16, 7:50 AM

Hello inian,

step 1: create a py file,

from datetime import datetime

start_work = fields.Datetime(string="Start work")

end_work = fields.Datetime(string="End work")

lunch_hour=fields.Integer(string="Lunch Hour")

work_hours=fields.Integer(string="Working Hour",compute='sal_cal',store=True)

total_hour=fields.Integer(string="Total Hour")

per_hour = fields.Integer(string="Per Hour")

salary=fields.Integer(string="Salary")

Create a compute function name as sal_Cal

@api.depends('start_work','end_work')

def sal_cal(self):

t1= datetime.strptime(self.start_work, '%Y-%m-%d %H:%M:%S')

t2= datetime.strptime(self.end_work, '%Y-%m-%d %H:%M:%S')

res= datetime.strptime(str(t2.time()),'%H:%M:%S') - datetime.strptime(str(t1.time()),'%H:%M:%S')

s=':'.join(str(res).split(':')[:1])

self.work_hours=s

Create a onchange function,

@api.onchange('work_hours','per_hour','lunch_hour')

def funa(self):

if self.per_hour and self.work_hours:

self.total_hour=(self.work_hours-self.lunch_hour)

self.salary=self.per_hour*self.total_hour

step 2: Create a view File, please paste a code in your tree and form view,

<group>

<field name="start_work" />

<field name="end_work" />

<field name="work_hours" />

<field name="lunch_hour"/>

<field name="total_hour"/>

<field name="per_hour" />

<field name="salary" />

</group>

Step 3: See the output of the program

 Start work 06/09/2016 08:42:16 End work 06/01/2016 17:19:43 Working Hour 8 Lunch Hour 1 Total Hour 7 Per Hour 60 Salary 420

How to Proceed this Codeing. Please Explain Brefly or Step by step.

Mohan
on 9/1/16, 6:43 AM
Mohan
On 9/1/16, 6:37 AM

Salary calculation on the basis of Hours the employees worked | Odoo9

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.

2 follower(s)

### Stats

 Asked: 6/6/16, 3:37 AM Seen: 1075 times Last updated: 9/1/16, 6:37 AM