Odoo Qweb template development workflow and best practices

Viewed 191

Senior dev learning Odoo 15 for the first time. I've been frustrated by my lack of productivity with Qweb and what should be very basic tasks of overriding the default layouts and html in my own custom theme module. I feel I would be much more efficient if I could answer the following questions:

  • How can you generate a complete list of all the template id's in the registry?

  • With a known template id, how can you find the XML file that generated that template?

  • If I inspect my site with web developer tools, how can I find the Qweb template id that generated any particular HTML element?

  • How can I override any builtin QWeb template with a custom template that replaces or modifies any particular HTML child element? I think this is done through a combination of template inheritance and XPath.

  • Can you share any of your QWeb development tips and tricks?

1 Answers
  1. Have you looked at "Settings > Technical > User Interface > Views" (debug mode)? You can view all the views Odoo uses.
  2. After finding the view you need to inherit, you can search for the view's external id through your server or github for the related xml file in the source code (ie 'grep -R "invoice_form" *).
  3. You can inherit any view in a custom module and modify it as needed.

Qweb:

 <template id="products_custom" inherit_id="website_sale.products" name="Products">
        <xpath expr="//h3[@class='css_editable_display']" position="replace">
           ...
        </xpath>
  </template>

Form view:

<record id="account_invoice_form_custom" model="ir.ui.view">
    <field name="name">account.invoice.form.custom</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form" />
    <field name="arch" type="xml">
        <field name="partner_id" position="after">
             <field name="custom_field"/>  
        </field>
    </field>
</record>
  1. Check out these links for more info about inheriting xml views. https://doc.odoo.com/6.0/developer/2_6_views_events/views/view_inheritence/ https://www.odoo.com/forum/help-1/how-to-inherit-view-in-existing-module-94801
Related