This question has been flagged
1 Reply
2579 Views

Hi Friends,

I am using openerp 6.1 version.I had wrote a fields.function for calculating no of days based on start_date,end_date.It prints the result but it showing the error as RuntimeError: maximum recursion depth exceeded

    def _total_hours(self, cr, uid, ids, field_name, args, context=None):
        for days in self.browse(cr,uid,ids, context=context):
            a = datetime.datetime.strptime(days.start_date, "%Y-%m-%d")
            b = datetime.datetime.strptime(days.end_date, "%Y-%m-%d")
            delta = b - a

            days.write({'no_days':delta.days+1})
        return True

 

So please instruct me to rectify this error ASAP.Thanks in Advance

 

Avatar
Discard
Best Answer

Your return is incorrect.  Don't write the no_days but collect it in a dictionary and return the value:

    def _total_hours(self, cr, uid, ids, field_name, args, context=None):

       res = {}
        for days in self.browse(cr,uid,ids, context=context):
            a = datetime.datetime.strptime(days.start_date, "%Y-%m-%d")
            b = datetime.datetime.strptime(days.end_date, "%Y-%m-%d")
            delta = b - a

            res[days.id] = delta.days+1
        return res

Avatar
Discard

Not sure what causes the recursion error though. It may be something else.

Author

Thank you friend (Ivan). It saved me a lot of time!!!!!!!!!!!!!!!!!!!

Glad to help.