Skip to Content
Menu
This question has been flagged
2 Replies
7037 Views

How to calculate hours based salary for employee?

please Help me

Avatar
Discard
Best Answer

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

06/09/2016 08:42:16
06/01/2016 17:19:43
8
1
7
60
420
Avatar
Discard

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

Best Answer

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

Avatar
Discard