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

Funtional field is not detching value for field Showing error?

By
vadivel
on 1/23/15, 2:14 AM 505 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

 

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/23/15, 2:30 AM

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

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

Ivan
on 1/23/15, 2:31 AM

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

vadivel
on 1/24/15, 12:50 AM

Glad to help.

Ivan
on 1/24/15, 1:04 AM

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

1 follower(s)

Stats

Asked: 1/23/15, 2:14 AM
Seen: 505 times
Last updated: 3/16/15, 8:10 AM