Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
48289 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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', ],

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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>

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

hahaha same error. I use

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

Tác giả

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.

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?

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...

Câu trả lời hay nhất

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

Only in view templates.

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 15
4362
1
thg 3 15
14427
3
thg 3 15
17950
0
thg 3 15
3474
11
thg 4 23
92941