Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Inherit Qweb

By
Alex
on 6/12/14, 3:50 AM 10,837 views

In the new report module we have the company external header in /views/layouts.xml. Its ID is report.external_layout_header. If I edit the view directly in Odoo, it changes but now I want to inherit it in a module and I am not able to do that. I am not a coder so maybe it's a dummy problem.

This is the original view:

<t t-name="report.external_layout_header">
    <div class="header">
        <div class="row">
            <div class="col-xs-3">
                <img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
            </div>
            <div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
        </div>
        <div class="row zero_min_height">
            <div class="col-xs-12">
                <div style="border-bottom: 1px solid black;"/>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-3">
                <div t-field="company.partner_id" t-field-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: true}" style="border-bottom: 1px solid black;"/>
            </div>
        </div>
    </div>
</t>

 

So I create my module with empty __init__.py and I call the qweb view in __openerp__.py like this:

'qweb': ['views/my_layouts.xml',],

In my_layouts.xml I extend the view like this:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

<templates>

<t t-extend="report.external_layout_header">
            <t t-jquery="div.header" t-operation="replace">

            <<MY CODE>>

            </t>
</t>

</templates>

    </data>
</openerp>

But not works. I can install my module without error but the header doesn't change. I don't know where is the error so any help is appreciated. Thank you.

4
Artur Bertram
On 8/4/14, 10:17 AM

Try it with the following code in your "views/my_layouts.xml".

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="report_header_custom" inherit_id="report.external_layout_header">
            <xpath expr="//div[@class='header']" position="replace">
                <div class ="header">
                    Your Code
                </div>
            </xpath>
        </template>
    </data>
</openerp>

Add the report in youre "__openerp__.py" file in the data.

'data': ['views/my_layouts.xml',],

And dont forget the depends.

'depends': ['base_setup',  'report', ],

0
Peter Nietz
On 6/13/14, 7:15 AM

Hi, do you use <templates>  ...   </templates>  in your qweb xml? It is needed.

Another thing could be a dependency. In the __openerp__.py give the dependencies to the report module like:

'depends':['whaterver_report',],

andalso in your __init__.py import ur custom_module.py if one is used.

Then try this in your xml template file:

<templates>

<t t-extend="report.external_layout_header">
            <t t-jquery=".header" t-operation="replace">

                  <div class="header">
                      <div id="change_test"/>

                           <<< your code >>>

                  </div>

            </t>
</t>

</templates>

Yes, I use tag. I edit my post sorry. Don't I need to use them?

Alex
on 6/13/14, 7:42 AM

hahaha same error. I use

Alex
on 6/13/14, 7:43 AM

The tag must be used. Otherwise your code looks fine. I will try to reproduce your problem and have a look at it.

Peter Nietz
on 6/13/14, 7:49 AM

Thank you so much Peter. Furthermore I am just testing so I am not adding difficult code, just deleting for example the company tagline. So I can't understand where is the problem.

Alex
on 6/13/14, 8:01 AM

Inheritence of QWEB isn't very intuitiv ... I now experience the problem that the template from which I inherit produces errors even though I didn't change anything in it, but only my custom template ... why?!?!? So code of my custom modul is now used in standard modules... so where is the point of inheritance?

Peter Nietz
on 6/17/14, 9:56 AM

I edited my answer, try it and then take a look with fe. firebug if the id change_test is included. For me this worked. Hope it helps u...

Peter Nietz
on 6/18/14, 5:39 AM
0

tolstoj

--tolstoj--
899
| 6 5 8
Germany
--tolstoj--

hi

tolstoj
On 6/13/14, 9:28 AM

I think you don't need <openerp> and <data> tags in qweb templates.

Only in view templates.

Maybe they are not necessary because if I delete them I have no install error, but don't solve the main problem. Here there is someone with the same problem. https://www.odoo.com/forum/Help-1/question/Edit-the-qweb-template-with-a-custom-modul-54304

Alex
on 6/14/14, 5:27 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

5 follower(s)

Stats

Asked: 6/12/14, 3:50 AM
Seen: 10837 times
Last updated: 8/28/15, 2:44 AM