Odoo Help


How to inherit a class in web module? [Closed]

on 5/6/13, 10:39 AM 5,318 views

The Question has been closed

on 05/28/2013 03:02:32

How to inherit a class in web module? I am trying to override the function

def index(self, req, action, token):


class Reports(View):

which is under web/controllers/main.py

On 5/23/13, 11:49 AM

I chose to create a new namespace as follows. Within the directory for the web addon create your own directory "myweb". Add python files __init__.py and "mycontroller.py" to the new directory. Edit the __init__.py with 'from . import mycontroller'. Back up to the web directory and edit the __init__.py file there with 'import myweb'. Now edit mycontroller.py with 'from .. import http' and 'myweb = http'. Then make a class

class MyWebController(myweb.Controller):
    _cp_path = '/web/myweb'
    def index(self, req, action, token):
        """ add your modified copy of index here """

At http://mydomain/web/myweb/ you'll hit your customized index. Now you have a nice sandbox for developing your own web module without interfering with existing web module functionality. You can copy out anything you need from main.py that you might want to reuse. I found it helpful to copy Session from it so I could override authenticate and have it return certain data I required upon login. Also copy all of the imported libraries from main.py too as they are all useful if not required.

Of course you can also be lazy and just add

class MyReports(View):
_cp_path = "/web/myreport"

to main.py.

Thanks Mike. I'll try it out..

on 5/24/13, 3:23 AM

Thanks again Mike..I used the same cp_path in base module and it worked..

on 5/24/13, 5:03 AM

Very cool! Good thinking Shelton!

on 5/24/13, 10:40 AM

Hi mike can you check my module but this does not works. https://code.launchpad.net/~ovnicraft/web-addons/6.1-web_report_name

AYNI CONSULTORES 1792538289001
on 6/15/13, 5:33 PM

Hi Mike, I have a problem in inherit class in web module. According to your answer, I did the following: 1. I have __init___.py & __openerp__.py &myweb folder in the new module, in _init_.py (import myweb), in openerp.py (depends=['web']) 2. in myweb folder, I have init.py(from . import mycontroller) & mycontroller.py(use the same content you provide). However, I can easily install the module, but the functions didn't change. Do you know why is that? do I need to add '_inherit = 'web' in mycontroller.py file? Please provide help and thanks a million!

on 11/15/13, 5:16 AM

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

0 follower(s)


Asked: 5/6/13, 10:39 AM
Seen: 5318 times
Last updated: 3/16/15, 8:10 AM