Odoo Help


How to override this method definition who is NOT in a class?

Pascal Tremblay
on 10/2/15, 10:28 AM 892 views

Hello all,

    In the file :


    There is the method :

        def login_redirect()

            url = '/web/loginPTPTPTPT555?'

            # built the redirect url, keeping all the query parameters of the url

            redirect_url = '%s?%s' % (request.httprequest.base_url, werkzeug.urls.url_encode(request.params))

            return """<html><head><script>

            window.location = '%sredirect=' + encodeURIComponent("%s" + location.hash);


            """ % (url, redirect_url)

How to override such a method who is not in a class?

Axel Mendoza
On 10/2/15, 11:36 AM

This is what it's called monkey patch. (https://en.wikipedia.org/wiki/Monkey_patch)

Like this:

from openerp.addons.web.controllers import main
def new_login_redirect():
main.login_redirect = new_login_redirect

very interesting. Will try it soon. Thanks again Axel!

Pascal Tremblay
on 10/2/15, 11:37 AM

Is this a good way to work or not?

Pascal Tremblay
on 10/2/15, 11:46 AM

Obviously is not the first choice and is not good if you have another way to do it, if you don't have an alternative? You can go with this method, I used, Gevent used and I'm sure more people is using it.

Axel Mendoza
on 10/2/15, 11:51 AM

It works. thanks again.

Pascal Tremblay
on 10/2/15, 12:00 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 10/2/15, 10:28 AM
Seen: 892 times
Last updated: 10/2/15, 12:03 PM