Odoo Help

Welcome!

This community 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.

0

Hours based salary for employee

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

How to calculate hours based salary for employee?

please Help me

2
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

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

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

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

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

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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