Odoo Help


Conditional Formatting on Reports using QWeb

Shawn Varghese
on 1/12/15, 8:43 AM 5,787 views

I need to conditionally format a report template for Quotation:

....<tbody class="sale_tbody">

<t t-foreach="o.order_line" t-as=i">

<tr t-if="something">                     // <<< Have to set CSS depending on condition here

<td><span t-field="i.name" /></td>



In the code snippet, I basically want to change the background colour of the row based on a value in the order_line table (like quantity less than 4 etc.)

I have been struggling to do it. I have tried to use t-if and t-att, but I can't understand how to change CSS format with the conditions.

Can anyone please help me out on this?



Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 1/12/15, 10:02 AM

You have to write to conditions to change the formating.

<tbody class="sale_tbody">
    <t t-foreach="o.order_line" t-as=i">
        <tr t-if=="value1">                     
            <td><span t-field="i.name" /></td> // <<< Have to set CSS depending on condition here
        <tr t-if=="value2">                     
            <td><span t-field="i.name" /></td> // <<< Have to set CSS depending on condition here


Shawn Varghese

--Shawn Varghese--
| 5 3 7
Dubai, United Arab Emirates
--Shawn Varghese--

Shawn Varghese
On 1/24/15, 5:53 AM

There is actually a better way to do this, as I just found out:

<t t-if-"value1">
      <t t-set="style" t-value="'color:blue'" />
<t t-if-"value2">
      <t t-set="style" t-value="'color:red'" />
<span t-att-style="style" >Test</span>


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

2 follower(s)


Asked: 1/12/15, 8:43 AM
Seen: 5787 times
Last updated: 3/16/15, 8:10 AM