Search code examples
python-3.xodoo-11odoo-view

reuse form, tree, kanban view in the website module


I'm working in odoo-11, I have created a module my_contact where I extend from res.partner to add the fields I need, like facebookId, emailVerified, maritalState, etc., and I have modified the views form, tree, etc., to show the new fields, this is the example of the extended form view:

<record id="res_partner_form_inherit" model="ir.ui.view">
        <field name="name">My Contact Form</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <field name="vat" position="before">                    
                <field name="marital_state"/>
            </field>
            <field name="email" position="before">
                <field name="facebook_id"/>
            </field>
            <field name="email" position="after">
                <field name="email_verified"/>
            </field>
        </field>
    </record>

up here all right. I need to make a website where I show all the contacts, for that I specify that my module 'my_contact' depends on the website module, I would like to reuse the views I have extended, to show the form view previously shown, I do the following:

  1. I create the website.page:

    <record id="contact_index_page" model="website.page">
        <field name="name">Contact Index Page</field>
        <field name="website_published">True</field>
        <field name="url">/contacts</field>
        <field name="view_id" ref="res_partner_form_inherit"/>
    </record>
    
  2. I create a website.menu to navigate to the view:

    <record id="my_contact_menu" model="website.menu">
        <field name="name">Contacts</field>
        <field name="page_id" ref="contact_index_page"/>
        <field name="parent_id" ref="website.main_menu"/>
    </record>
    
  3. I create a path in the controller to render the view:


@http.route('/contacts', auth='user', website=True)
def index(self, **kw):
    return http.request.render('my_contact.res_partner_form_inherit')

I check in the external identifiers that the path '/contacts' in the controller executes the view that I created by extending the original view, however, when I navigate to the path '/contacts' it says: ValueError: View 'my_contact.res_partner_form_inherit' in website 1 not found.


Solution

  • The error is because you cannot reuse a form view to be rendered with Qweb Engine as if it's defined as a template. The call to request.render it's intended to render templates(qweb views). It's not possible in Odoo out of the box