Search code examples
javascriptreportodooodoo-11qweb

ODOO report automatically convert character < as &lt;


I have a character type field which its value sometimes contain <,> or &, when I use report, odoo automatically convert it as &lt;.

I have tired use js export and import to get an external function to convert. (I can not put this function in view template, because if the template contain <,> or &, python interpreter can't parse file with these characters.)

var convert= function (str) {
return str.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
                    };


export {convert};

this file path is my_module/static/src/js/js1.js And in same module I have a view template import it as:

<script type="text/javascript">
import {convert} form "/my_module/static/src/js/js1.js"
.
.
.
    <t t-foreach="docs" t-as="doc">
        <t t-esc="doc.surfhrd"/>
.
.
.

And get no data since import line is added.

I expect this can convert the html character to its origin appearing.

And I sure this function can work that I have tested in browser's developer tools console.


Solution

  • I found solution in here.

    enter image description here

    <t t-foreach="docs" t-as="doc">
        \\<t t-esc="doc.corehrd"/>
        <t t-raw="doc.corehrd"/>
    

    replace t-esc as t-raw