Enable Dark Mode!
basic-qweb-operations-in-odoo-15.jpg
By: Aswathi PN

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



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message