0
votes

I have written this function to update separate table and it dosn't work. With debugging mode on it returns the values.

I need to update separate table (leave_score_card table) with each and every employees accumulated number of days which taken leaves against to leave type like I have shown in following picture and Data will be taken from original hr_holidays table in Leave Management Module

enter image description here

Please help me to make this right. It shows only the last record and what I have tried so far is mentioned bellow

 def populate_values(self, cr, uid, ids, context={}):

        result = {'value': {}}
        emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
        if emps:

            for r in emps:

                print r
                result['value']['employee_id'] =r
                holiday_obj=self.pool.get('hr.holidays')
                holiday_emps=holiday_obj.search(cr, uid, [('employee_id','=',r),('type','=','remove')], context=context)
                print holiday_obj
                global medi
                global annu               
                global othr


                print holiday_emps
                if holiday_emps:
                    casu = 0
                    annu=0
                    medi=0
                    other=0 

                    for n in holiday_obj.browse(cr, uid, holiday_emps):


                       holiday_status = n.holiday_status_id.id
                       holiday_days=n.number_of_days_temp
                       print n
                       print n.holiday_status_id.id
                       print "Number of days"
                       print n.number_of_days_temp

                       if holiday_status:
                           if holiday_status==2:  
                                casu=casu+holiday_days

                           if holiday_status==4:
                                medi=medi+holiday_days

                           if holiday_status==10:
                                annu=annu+holiday_days

                           else:
                                other=other+holiday_days

                       else:
                           print "Un-identified leave Type"


                    result['value']['taken_medical'] =medi
                    result['value']['taken_casual'] =casu
                    result['value']['taken_anual'] =annu
                    result['value']['taken_other'] =other


        return result     
1
Why you return False ?Kenly
Sorry I forgot to edit that out , I used 'result' as return , but it only returned one record. Btw, I have updated the question.Swan White
What are you trying to update here? How is this function called?CZoellner
I need to update separate table with each and every employees accumulated number of days which taken leaves against to leave type like I have update (showed) in the question. Data will be taken from original hr_holidays table in Leave Management ModuleSwan White
And how is it called? Could you please provide the code behind the call?CZoellner

1 Answers

0
votes

Basically I have used create and write methods to populate the DB which is follows;

 def populate_values(self, cr, uid, ids, context={}):

        result = {'value': {}}
        emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
        if emps:

            for employees in emps:

                result['value']['employee_id'] = employees
                holiday_obj=self.pool.get('hr.holidays')
                holiday_emps_allocate=holiday_obj.search(cr, uid, [('employee_id','=',employees),('type','=','add')], context=context)
                holiday_emps_taken=holiday_obj.search(cr, uid, [('employee_id','=',employees),('type','=','remove')], context=context)



                if holiday_emps_allocate:
                    casu_allo=0
                    annu_allo=0
                    medi_allo=0
                    other_allo=0

                    for a in holiday_obj.browse(cr, uid, holiday_emps_allocate):
                        holiday_status_allo = a.holiday_status_id.id
                        holiday_days_allo=a.number_of_days_temp

                        if holiday_status_allo:
                            if holiday_status_allo==2:  
                                casu_allo=casu_allo+holiday_days_allo

                            if holiday_status_allo==4:
                                medi=medi_allo+holiday_days_allo

                            if holiday_status_allo==10:
                                annu=annu_allo+holiday_days_allo

                            else:
                                other_allo=other_allo+holiday_days_allo

                        else:
                            raise osv.except_osv(_('Warning!'),_('Un-Identified Leave Allocation'))


                print holiday_emps_taken
                if holiday_emps_taken:
                    casu = 0
                    annu=0
                    medi=0
                    other=0 

                    for n in holiday_obj.browse(cr, uid, holiday_emps_taken):


                       holiday_status = n.holiday_status_id.id
                       holiday_days=n.number_of_days_temp
                       print n
                       print n.holiday_status_id.id
                       print "Number of days"
                       print n.number_of_days_temp

                       if holiday_status:
                           if holiday_status==2:  
                                casu=casu+holiday_days

                           if holiday_status==4:
                                medi=medi+holiday_days

                           if holiday_status==10:
                                annu=annu+holiday_days

                           else:
                                other=other+holiday_days

                       else:
                           raise osv.except_osv(_('Warning!'),_('Un-Identified Leave.'))

                casu_rem=casu_allo-casu
                medi_rem=medi_allo-medi
                annu_rem=annu_allo-annu

                score_obj=self.pool.get('leave.score.card')
                score_objs=score_obj.search(cr, uid, [('employee_id','=',employees)], context=context)                
                score_objss = score_obj.browse(cr, uid, score_objs, context=context)

                if score_objs:
                    self.write(cr,uid,score_objs[0],{
                                                 'taken_medical':medi,
                                                 'taken_casual':casu,
                                                 'taken_annual':annu,
                                                 'taken_other':other,
                                                 'available_medical':medi_rem,
                                                 'available_casual':casu_rem,
                                                 'available_annual':annu_rem}) 


                else:
                    self.create(cr, uid, {'employee_id':employees,
                                                 'taken_medical':medi,
                                                 'taken_casual':casu,
                                                 'taken_annual':annu,
                                                 'taken_other':other,
                                                 'available_medical':medi_rem,
                                                 'available_casual':casu_rem,
                                                 'available_annual':annu_rem})


        return result   

the bottom most parts are got changed