James Kowaich
James Kowaich

Reputation: 65

Can't Inherit Odoo theme template

I have Base theme called theme_test Here is the template code(this template is added in manifest's data).

<template id="product_catg_test" name="Product Category">
    <t t-if="categories">
        <code for print category>
    </t>
</template>

So I have created an extended module called test_theme_extended and tried two inherit approach to replace the t-if condition

  1. First Approach(I added this file in data in the manifest)
<template id="product_catg_test_extended" inherit_id="theme_test.product_catg_test" name="Test">
    <xpath expr="//t[@t-if='categories']" position="replace"></xpath>
</template>

This first approach gives me an error

odoo.tools.convert.ParseError: "Element '' cannot be located in parent view

  1. Second Approach(I added this file in QWEB in the manifest)
<t t-extend="theme_test.product_catg_test">
    <t t-jquery="t[t-if='categories']" t-operation="replace"/>
</t>

This also not working.

I am thinking that the main view created from the theme and it has no external ID that's why I face this issue. But how can I inherit the base theme view in extended module?

Upvotes: 4

Views: 1940

Answers (2)

If you are inheriting a theme it has to be from another theme, or use a record instead of template.

Defining a theme, as with a theme prefix and in the thema category enter image description here

Since a module-theme creates the views in theme ir_ui_view and creates copies without XMLID in ir_ui_view

and a normal module creates the views in ir_ui_view

So if from a normal module (ir_ui_view) you want to modify a view-theme (theme_ir_ui_view) then literally it will not find the element because it is in another table

but if you still want to try you can do the inheritance in this way, inheriting the copies that do not have the XML so you have to do the inheritance by the key

<record id="product_catg_test_extended" model="ir.ui.view">
    <field name="name">product_catg_test_extended</field>
    <field name="inherit_id" search="[('key', '=', 'theme_test.product_catg_test')]"/>
    <field name="type">qweb</field>
    <field name="key">test_theme_extended.product_catg_test_extended</field>
    <field name="arch" type="xml">
        <xpath expr="//t[@t-if='categories']" position="replace"></xpath>
    </field>
</record>

Upvotes: 6

OlafW
OlafW

Reputation: 710

currently I'm struggeling with the exact same problem. So far when debugging the code responsible for the lookup I wondered why the content of the parent view is not the same as the xml shows.

Long story short: The templates from theme modules are NOT stored as ir.ui.view but as theme.ir.ui.view. The code will lookup with the wrong ID as it expects a regular view - either finding the wrong regular view or finding nothing.

Unfortunately I did not find any solution to modify a theme.ir.ui.view - if someone has a solution I would really appreciate if she/he shares it with us.

It seems the only way to modify a theme is to edit the original xml files.

UPDATE:

I've tried to work with a different approach like I inherit form views (<record model='theme.ir.ui.view />) but this only created the record in the table theme_ir_ui_view but did not triggered the inheritance mechanisms.

For now I've created a new xml inside the theme I want to modify and have to live with that. Maybe a custom module named 'theme_XXX' could also inherit a theme template but I have to go on with my project.

Upvotes: 1

Related Questions