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

What is XmlHttpRequestError INTERNAL SERVER ERROR?

By
Anirudh Lou
on 8/4/15, 4:30 AM 560 views


I made a method for an on_change method and here is my method for it.

    def onchange_date_start(self, cr, uid, ids, date_start, context=None):
factor = 2
date_1 = datetime.strptime(date_start, '%Y-%m-%d')
date2 = date_1.date()
end_date = datetime(date2.year,date2.month,date2.day) + relativedelta(months=+factor)
e_date = end_date
_logger.info("\n\t\t\t\tEND Date Final %s"%(str(e_date.date())))
value = {"value":{"end_on" : e_date.date()}}
return value

 

So far it print out my **e_date** correctly but an error also pop saying:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<h1>Internal Server Erro</h1>
<h1>Internal Server Error&lt</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

and here is what the terminal says:

        raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.date(2015, 10, 18) is not JSON serializable

What error i committed?

Thanks for any help/suggestion

1

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 8/4/15, 5:28 AM

 you should strftime back to the string a date, after you calculate it.

Try this (you do too mush work):

 def onchange_date_start(self, cr, uid, ids, date_start, context=None):
        factor = 2
        date = datetime.strptime(date_start, '%Y-%m-%d') + relativedelta(months=factor)
return {"value":{"end_on" : date.strftime('%Y-%m-%d')}


OR in terms of your code:

 def onchange_date_start(self, cr, uid, ids, date_start, context=None):
        factor = 2
        date_1 = datetime.strptime(date_start, '%Y-%m-%d') 
        date2 = date_1.date() 
        end_date = datetime(date2.year,date2.month,date2.day) + relativedelta(months=+factor) 
        e_date = end_date 
        _logger.info("\n\t\t\t\tEND Date Final %s"%(str(e_date.date()))) 
        value = {"value":{"end_on" : e_date.strftime('%Y-%m-%d')}} 
        return value

@Temur , Thanks it works.

Anirudh Lou
on 8/4/15, 9:12 PM

and also for making it shorter. :)

Anirudh Lou
on 8/4/15, 9:13 PM

You're welcome

Temur
on 8/5/15, 4:47 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: 8/4/15, 4:30 AM
Seen: 560 times
Last updated: 8/4/15, 9:10 PM