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

HR Payroll Pay Roll - Python Rules.

By
Gavin Yap
on 6/28/15, 4:17 AM 915 views

How do I get the age of the employee when defining a salary rules like 

if age < 35:

result = 0.17 * categories.BASIC

elif age >= 35 and age < 45:

result = 0.17 * categories.BASIC

elif age >= 45 and age < 50:

result = 0.17 * categories.BASIC

elif age >= 50 and age < 55:

result = 0.16 * categories.BASIC

elif age >= 55 and age < 60:

result = 0.12 * categories.BASIC

elif age >= 55 and age < 60:

result = 0.085 * categories.BASIC

elif age > 65:

result = 0.075 * categories.BASIC

0
Gavin Yap
On 6/29/15, 12:59 AM

I have to edit code  to openerp/addons/hr/hr.py

import time
from datetime import datetime
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
...
class hr_employee(osv.osv):
    _name = "hr.employee" 
    _description = "Employee" 
    _order = 'name_related'
    _inherits = {'resource.resource': "resource_id"}
    _inherit = ['mail.thread']

...

    def get_age(self):
        if not  self.birthday:
            return 0
        birth = datetime.strptime(self.birthday, DEFAULT_SERVER_DATE_FORMAT)
        today = datetime.strptime(time.strftime(DEFAULT_SERVER_DATE_FORMAT), DEFAULT_SERVER_DATE_FORMAT)
        delta = today - birth
        return delta.days / 365

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

1 follower(s)

Stats

Asked: 6/28/15, 4:17 AM
Seen: 915 times
Last updated: 6/29/15, 12:59 AM