Odoo Help

0

How to use t-if to detect report printing?

By
Pascal Tremblay
on 08/09/17 06:57 450 views

Hello there,

We are on Odoo 8.

I wrote a module to manage Facebook an Twitter metatags. My module works well with the frontend when I share a link on these social network.

My problem is when I try to print an invoice, a sale order or an other PDF from the backend. I get the below error.

In my module, my layout inherits website.layout (see below). It seems that this website.layout is also used to print PDF reports in the backend.

Question :

How could I use a t-if condition in my code to detect when Odoo is printing a report? 

or

How could I call my new code only on the front-end? Not when printing a report.


Thanks for your help!


My module code :

        <template id="title_metas">
            <t t-if="not seo_site_name">
                <t t-set="seo_site_name" t-value="website.name" />
            </t>
         [........ many codes here.......]
        </template>

        <template id="layout" inherit_id="website.layout">
            <xpath expr="//title" position="after">
                <t t-call="title_metas" />
            </xpath>
        </template>


Error :

QWebException: "'NoneType' object has no attribute 'name'" while evaluating 'website.name'



EDIT #1

For the moment, we'll use this new "t-if" condition. So, in the back-end, when we are printing a PDF report (sale order, invoice or other), our new template "title_metas" is not called and the above error is avoid.

Would you have a best way to avoid the above error?

                <xpath expr="//title" position="after">
                    <t t-if="website and website.name">
                        <t t-call="title_metas" />
                    </t>
                </xpath>




About This Community

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

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 08/09/17 06:57
Seen: 450 times
Last updated: 21/10/17 15:08