Odoo Help


How to use t-if to detect report printing?

Pascal Tremblay
on 08/09/17 06:57 851 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? 


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" />
         [........ many codes here.......]

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

Error :

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


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" />

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.


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)


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