Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Enable Dark Mode!

JUN 22,2022

Basic Qweb Operations in Odoo 15


Technical Odoo 15

Qweb is a reporting or template engine that can be used to build reports. Odoo uses
Qweb to generate reports.web has a number of tools for making reports. We may
easily alter the data by utilizing Qweb.

We'll go over the fundamental features of Qweb for making reports. For the
operations, we use XML attributes prefixed with 't-'.We may construct a new
variable, set a value to it, and utilize it in our template just like any other
programming language.

Define a Variable

First of all we can discuss how to define a variable in Qweb

We can use t-set to define a variable and the basic syntax to define a variableid

<t t-set="variable_name" t-value="value of the variable" />

Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
For Example

<t t-set="word_count" t-value='1'/>

Here we can see that create a variable with name word_cound also assign its value
as one it is a static value

We can set the value as dynamic using some functions

<t t-set="word_count" t-value='word_count()'/>

Here the value of the word_count variable is the value that is returned from a
function that we specified on the above code ‘word_count()’.

We do not need to indicate the variable type when we define it. In Odoo, we can have
a variety of variables, including numbers, texts, arrays (lists), and dictionaries,
among others. If we need to define a dictionary, we can use the following code to
accomplish so:

<t t-set="new_dict" t-value="{'first': '1', 'second': '2' }" />

We can also make lists in the same way. A loop can be used to iterate over the
different values of a list or dictionary.

Find Output

In order to get the output a value, qweb provides two directives that are t-esc and t-
raw. The commonly used directive is t-esc.

Example of t-esc:

<t t-esc="values"/>

Example for t-raw:

<t t-raw="myvar"/>

t-esc operation will evaluate the variable and get the content of that variable. The
primary distinction between t-esc and t-raw is that t-esc will automatically HTML-
escape its text, whereas t-raw will not.

Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Conditional Operators

We can work some conditions over a function or print a variable for that we can use
conditional operations. Mainly we use t-if

The basic syntax is as below:

<t t-if="Condition"><code that run after satisfy the condition></t>

For example

<t t-if="count==0"><t t-set="count" t-value="1"/></t>

The above example checks whether the value of the count equals zero or not. That
will equal to zero code getting inside the condition and working the code inside the
condition otherwise it will not work.

At a time we can check multiple conditions

Example:

<t t-if="not (count==0 or count ==1)"><t t-set="count" t-value="1" /></t>

Here there are two conditions that are checked either the first or second is satisfied
the code will get inside the condition.

Loops

We may need to iterate over a set of values in some circumstances. If we have a list
or a dictionary and need to iterate through each value, we can do so with t-for each.

<t t-foreach="[1,2,3,4,5] t-as="i">


<t t-esc="i"/>
</t>

Get the output of the code is print all elements in [1,2,3,4,5]

Calling other templates

t-call directive is mainly used for calling other templates from qweb. This can be
used in a template or for top-level

Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
<t t-call="other_template"/>

The above discussed are some of the basic Qweb operations in Odoo. I hope that
everyone can get a basic idea about this topic.

If you need any assistance in odoo, we are online, please chat with us.

Whatsapp Chat Now

Share this article:

Related Blogs

0 Comments

Leave a comment
Name

Email

Website

Comment

Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Post Comment

CALICUT LONDON
Cybrosys Technologies Pvt. Ltd. Cybrosys Limited
Neospace, Kinfra Techno Park Alpha House,
Kakkancherry, Calicut 100 Borough High Street, London,
Kerala, India - 673635 SE1 1LB, United Kingdom

KOCHI BANGALORE
Cybrosys Technologies Pvt. Ltd. Cybrosys Techno Solutions
1st Floor, Thapasya Building, The Estate, 8th Floor,
Infopark, Kakkanad, Dickenson Road,
Kochi, India - 682030. Bangalore, India - 560042

SEND US A MESSAGE
Full Name

E-mail

Phone

Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Your Message

SEND

QUICK LINKS
Odoo

Odoo Apps

Odoo Success Pack

Odoo Partners

Buy Source code

Contact us

Sitemap

SERVICES
Odoo Customization

Hire Odoo Developer

Odoo Implementation

Odoo Integration

Odoo Support

Odoo Migration

Odoo Consultancy

Odoo Training

Odoo Licensing

REFERENCE
Odoo ERP

Odoo Software

Odoo vs SAP

Odoo vs Dynamics

Odoo vs ERP Next

Odoo vs Netsuite

Odoo vs Sage

Odoo vs Sugar CRM


Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Odoo vs Sugar CRM

Odoo vs Zoho CRM

STAY IN TOUCH
+91 8606827707

info@cybrosys.com

+91 8606827707

CONNECT SOCIALLY

Copyright © 2023 Cybrosys Technologies. All Rights Reserved. Privacy Policy

Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com

You might also like