This question has been flagged
2 Replies
3897 Views

_inherit = 'hr.payslip'

def prasent_days(self, cu, uid, ids, field_names, args, context=None):
    res={}
    temp = 0
    user_att = self.pool.get("hr.attendance")        
    for count in user_att.browse(cu, uid, ids, context=None):
        if count.name  >= date_from and count.name <= date_to:
            temp = temp + 1.0
    res[id]=temp 
    return res

_columns = {
       'es_present':fields.function(prasent_days, "No.of Present Days"),           
}
Avatar
Discard
Author Best Answer

Hi I am trying to count no of days the employee signed in so to count no of presents in the office in a month

please help me

I am thinking if i iterate through the hr.attendance module to count no of days

class esteem_payslip(osv.osv):
_inherit = 'hr.payslip'

def prasent_days(self, cr, uid, ids, field_names, args, context=None):
    res={}
    user_att = self.pool.get("hr.attendance")
    for slip in self.browse(cu, uid, ids, context=None):
        temp = 0
        att_ids = user_att.search(cu, uid, [('employee_id','=',slip.employee_id.id)])        
        for count in user_att.browse(cu, uid, att_ids, context=None):
            if count.name  >= slip.date_from and count.name <= slip.date_to: #This is not a good condition
                temp = temp + 1.0
        res[id]=temp 
    return res

_columns = {
       'es_present':fields.function(prasent_days, "No.of Present Days"),           
}

esteem_payslip()

this is not working

att_ids = user_att.search(cr, uid, [('employee_id','=',slip.employee_id.id)]) NameError: global name 'cr' is not defined

Avatar
Discard

The comment is edited, change cu to cr, it's done

Author

NameError: global name 'cr' is not defined

Author

This code is not working please help me

Best Answer
def prasent_days(self, cu, uid, ids, field_names, args, context=None):
    res={}
    user_att = self.pool.get("hr.attendance")
    for slip in self.browse(cu, uid, ids, context=None):
        temp = 0
        att_ids = user_att.search(cr, uid, [('employee_id','=',slip.employee_id.id)])        
        for count in user_att.browse(cu, uid, att_ids, context=None):
            if count.name  >= slip.date_from and count.name <= slip.date_to: #This is not a good condition
                temp = temp + 1.0
        res[id]=temp 
    return res

_columns = {
       'es_present':fields.function(prasent_days, "No.of Present Days"),           
}
Avatar
Discard
Author

att_ids = user_att.search(cr, uid, [('employee_id','=',slip.employee_id.id)]) NameError: global name 'cr' is not defined

Author

Please help with the above error