0
votes
javascript - ODOO report automatically convert character < as &lt; - Stack Overflow
Asked
Viewed 410 times
0

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.

2
  • have you seen this is suitable for your purpose?
    – Simo
    Jul 18 2019 at 7:54
  • I can not put function in template's script directly, so its solution will not work,either. Jul 18 2019 at 8:01
2

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

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.

     
    1
    have you seen this is suitable for your purpose?Simo
    I can not put function in template's script directly, so its solution will not work,either.Terrence Poe

    1 Answers

    2
    votes

    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