Search code examples
pythonodooopenerp-7

function field, maximum recursion depth exceeded


In order to create a module "hr_payroll_from_timesheet", I was trying to add a field so I can count number of hours if an employee works in Saturday or Friday.

class hr_timsheet_sheet(osv.osv)
_inherit = 'hr_timsheet_sheet.sheet'

def _woked_days(self,cr,uid,ids,field_name,args=None,context=None)
    sheet = self.browse(cr,uid,ids)
    for record in sheet:
        hr_sup= ["Saturday","Friday"]
        count = 0.0
        for line in record.period_ids:
             day = line.name
             year, month, day = (int(x) for x in day.split('-'))
             days = datetime.date(year,month,day)
             if days.strftime("%A") in hr_sup:
                   count += line.total_attendance
                   self.write(cr,uid,ids,{
                          'weekend' : count,
                           })
     return True

_columns = {
   'weekend' : fields.function(_worked_days,method=True,type='float',store=True)
}

I did try to implement this method by adding a new button and changing my field into 'weekend' : float(), and it did work very well, actually what I want is to make all this calculation only when I click on save button... thanks in advance


Solution

  • I like this idea you are tying to do, payslip from timsheet try this:

    class hr_timsheet_sheet(osv.osv)
        _inherit = 'hr_timsheet_sheet.sheet'
    
        def _woked_days(self,cr,uid,ids,weekend,args=None,context=None)
            sheet = self.browse(cr,uid,ids)
            for record in sheet:
                hr_sup= ["Saturday","Friday"]
                count = 0.0
                for line in record.period_ids:
                     day = line.name
                     year, month, day = (int(x) for x in day.split('-'))
                     days = datetime.date(year,month,day)
                     if days.strftime("%A") in hr_sup:
                           count += line.total_attendance
                     res[record.id] = count
             return True
    

    it will work even when keeping the arg field_name