How to manipulate time in Odoo Qweb Report

In Odoo Qweb report, you probably want to change the time to something else, like add few hours, or change the timezone, or so on. To do that, you would need to use ‘t-esc’ template attribute of Odoo. Here is an example of how to add 6 hours to the original timestamp and then convert the time to string to show the value according to the user preference:

<span t-esc="(o.date_done + datetime.timedelta(hours=6)).strftime('%d/%m/%Y %I:%M %p')"/>

o.date_done is getting the date_done from the picking that you are visiting.

How to Fix Locale Font Issue with Odoo Qweb Reports


When looking at the html report in Odoo, locale fonts look ok, but if you download the Qweb report to print in pdf format, it prints gibberish. How to fix that?


Odoo uses a templating engine for reporting called ‘Qweb’. Qweb can be used to generate two types of reports. One is HTML and the other is PDF. Odoo primarily uses Qweb engine to generate the HTML code. After that, it uses a tool called ‘wkhtmltopdf’ to convert the report to pdf and make it printable. Now when, we look at the HTML version of the report, fonts are shown based on Unicode supported browsers or the fonts you have installed on your computer. But when you try to convert this to PDF using wkhtmltopdf, that tool has to have exclusive access to those fonts to be able to convert them from HTML to pdf for you. As wkhtmlpdf command runs in the server you have installed Odoo, hence, you would need to install the font package in the server.

In my case, I required to install Bengali fonts. For CentOS, it is available under the lohit package, that contains several indian fonts including bengali. To install bengali font package in CentOS 7, use the following command:

yum install lohit-bengali* -y

Once done, your wkhtmltopdf should be able to read the bengali fonts from your html/qweb templates and able to convert them to PDF for you.