Search code examples
pythonodooodoo-8odoo-view

odoo 8 multiple page navigation controller


I have created a module in odoo 8. The purpose of module is to create a page with a link to another page. i mean at first the main template is rendered and then there is a link to sub page. everything works fine till the main page. i have controllers.py, models.py, views(default.xml). in my openerp.py the value of 'data' : 'views/default.xml'. The controller is :

@http.route('/test/', auth='public')
def index(self, **kw):
    return http.request.render('test.main',{ 'root':'/test' })

@http.route('/test/sub', auth='public')
def sub(self, **kw):
    return http.request.render('test.sub',{ 'root':'/test' })

in my template, u have two ids ( namely main and sub )

<openerp>
  <data>
       <template id='main'>
           <div class='body'>
                 test body 
                 click to go to next page : <a t-attr-href = "#{ root }/sub">Next Page</a>
           </div>
           <div class='footer'>
                 test footer 
           </div>
       </template>

       <template id='sub' inherit_id="main">
           <xpath expr="//div[@class='body']" position="replace">
           <div class="page">
               replaced data
           </div>
           </xpath>
       </template>
  </data>
</openerp>

Now when i run this code, i am seeing the main page already replaced not with link. the body is replaced by default. But i want that the body should be replaced when clicked on the link for sub page.

I am novice in odoo, so don't know anything about it.


Solution

  • Xpath do it work just after the updation of module( not at the time of rending the template )

    just use t-if in that case,Like:

    < t t-if ="not show_tab"> // original data </t>
    
    
    < t t-if ="show_tab"> // replaced data </t>
    

    render the keyword:show_tab from your controllers.

    One more thing it's my personal suggestion ,don't create two controller for just replacing a tab.

    A single controller can handle multiple route in odoo .Please try to follow the concept of DRY.