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

Fonction to do operation on fields.date

hr
By
Koffi KPONOUGLO
on 2/17/14, 10:37 AM 982 views

I want to calculate year between fields date_end and date_start on every contract of and employee and i to the following but i get typeError.

class hr_employee(osv.osv):
_inherit = 'hr.employee'

def seniority_computation(self, cr, uid, ids, field_name, timedelta, args, context=None):
    "Calculation of employee seniority"
    obj_contract = self.pool.get('hr.contract')
    contract_ids = obj_contract.search(cr, uid, [('employee_id','=',ids),], order='date_start', context=context)
    for contract in obj_contract.browse(cr, uid, contract_ids, context=context): 
        date_start = contract.date_start
        date_end = contract.date_end
        if not date_end :
            date_end = date.today()
        timedelta = date_end - date_start          
        age += int(str(timedelta/365)[:2])
        return age

_columns = {
    'seniority': fields.function(seniority_computation, type="float", string="Seniority")

}
_sql_constraints = [
    ('seniority', "CHECK(seniority=<30)", "The limit of seniority is 30 years")
]

Please can you help me to do this very simplily?

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

0 follower(s)

Stats

Asked: 2/17/14, 10:37 AM
Seen: 982 times
Last updated: 3/16/15, 8:10 AM