20% OFF UNTIL THE END OF THE YEAR Use Code: OFF20 for 20% Off! (excluding customizations and support packages)
How to resolve  the problem of displaying some characters as “,<,>,&

How to resolve the problem of displaying some characters as “,,&

Sometimes the user can face some problems while printing the labels which consist of some characters such as “,<,>,& in some of their field values. It is related to how Odoo handles reports content. Below we tried to summarize the reasons for this problem and some tips on how we can manually and temporarily fix it on example of “&” symbol.

This issue happened because Odoo does HTML-escape for every field used in QWEB reports (most likely to protect the system against XSS attacks). So, “&” will be replaced with “&amp;” (HTML representation of “&” symbol).

For PDF reports it doesn’t lead to any problems because Odoo uses wkhtmltopdf library to get PDF content from HTML content (and in HTML “&amp;” will look just like “&”). The problem will be only for ZPL reports because they are in plain text.

In older versions of Odoo (< 15.0) this behavior can be easily changed by changing “t-esc” directive with “t-raw” (Deprecated since version 15.0). It still can be used as a workaround (at least in Odoo 15.0 and 16.0):

But it may stop working in a newer version of Odoo, so the correct solution is to add a new field with the use of markupsafe.Markup. It’s not the easiest way but the only correct one. Let’s assume we need to render “name” field as-is from res.partner model, without any replacements. To do this we need to add special method like:

After that we will need to manually edit our label template to use the method instead of field:

As you can see, these changes require some programming knowledge and unfortunately, there is no easy way to automatically do the same steps with our Label Designer.

More details about this QWEB reports and problem: https://www.odoo.com/documentation/16.0/developer/reference/frontend/qweb.html#deprecated-output-directives


To summarize: the easiest way for now is to manually replace “t-esc” with deprecated “t-raw”. It works for the moment (in Odoo 16.0).

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *