Qweb is a templating engine or reporting engine which can be used to create reports.
Odoo uses Qweb for generating reports.
Qweb provides several tools for creating a report.
By using Qweb, we can manipulate the data very easily.
2. INTRODUCTION
• Qweb is a templating engine or reporting engine which can be used to create reports.
• Odoo uses Qweb for generating reports.
• Qweb provides several tools for creating a report.
• By using Qweb, we can manipulate the data very easily.
3. • Basic Features Available In Qweb For Creating A Report is discussed.
• We Use XML Attributes Prefixed By ‘T-’ For Performing The Operations.
• Just Like Any Other Programming Language, We Can Define A New Variable, Assign A
Value To It, And Use It In Our Template.
4. How to define a variable
t-set can be used to define a new variable and set its value.
Syntax is,
5. Example:
• This will create a new variable ‘count’ and set its value to zero.
• We can set the value of the value of this variable using a function.
6. • Here, the value of ‘count’ will be the value returned from the function ‘my_function’.
• When we define a variable, we don’t need to specify a specific type of this variable.
• We can have several types of values such as numbers, strings, arrays(lists) and dictionaries etc.
• If we need to define a dictionary, we can achieve it like this,
• Just like this, we can use lists also.
• Iterating over the different values of a list or dictionary can be achieved by using a loop.
7. Output
• In order to output a value, qweb provides t-esc and t-raw directives.
• The commonly used one is t-esc.
• t-esc will evaluate the variable and print the content of that variable
• The difference between t-esc and t-raw is, t-esc will automatically HTML-escape its
content while t-raw won’t.
8. Conditional Operators
• After setting a variable, we can perform our operations on that variable.
• We can use t-if to perform any conditional operations.
• The basic syntax is as follows.
9. Example:
• This will first check the value of ‘count’ is zero or not.
• If yes, the contents inside the t-if will be executed.
• The ‘else’ condition can be achieved by using a ‘not’ before the condition in the t-if
tag.
• The ‘not’ can be used to reverse the condition. i.e just like the else condition.
10. Example:
If we need to include multiple conditions, we can achieve this by using ‘and’ or ‘or’.
11. Loops
• In some cases, we may need to iterate over a set of values.
• Suppose we have a list or a dictionary with us and we need to iterate through
each value, in this case, we can use t-for each for this purpose.
• This will iterate over the list [1, 2, 3] and prints each element one by one.
12. Calling Other Templates
Calling other templates from qweb can be achieved using the t-call directive. This can
be used for top-level rendering or within a template.
13. Handling Fields
• When we are handling fields, we can use t-field directive ( the result of the browser
method).
• t-field-options can be used for customizing these fields.
• The widget is one of the most common options used with t-field options.
• We can have different types of widgets for different types of values.
14. Refer this link for more:
https://www.cybrosys.com/blog/basic-qweb-operations
15. Thank You !
Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park,
Kakkancherry,
Calicut University P.O.
Calicut
Kerala, India - 673635.
Cybrosys Ltd
15, ST Antonys Road,
Forest Gate, London
England,
E79QA.
Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, Kerala,
India-682030.