3

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?

Pierre
  • 1,129
  • 2
  • 16
  • 30
  • Try to use ` – Kenly Aug 29 '20 at 23:45
  • I already used it. Check the first approach in question. – James Kowaich Aug 31 '20 at 04:10
  • Try to use it without specifying the attribute. – Kenly Aug 31 '20 at 09:26
  • But I only want to replace t-if='categories', if I do not specify the attribute then it will replace the whole 't' tag. And one thing I notice by debugging base code, odoo take inherit template as its base template, not mine i.e. theme_test.product_catg_test – James Kowaich Sep 01 '20 at 10:43
  • If your template has only one `t`, the attribute is not needed. Check if you added `theme_test ` to `test_theme_extended` module dependency. – Kenly Sep 01 '20 at 13:09

2 Answers2

4

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>
  • 1
    Thank you so much it really helps a lot and sorry for not giving upvote because I don't have enough reputation. You really made my day. – James Kowaich Jun 30 '21 at 11:37
1

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.

OlafW
  • 700
  • 6
  • 22