Help

1

How to replace carriege return \n or \r or both into html <br> in a qWeb pdf report? (Odoo9)

Avatar
Andreas Jonderko

In an sale order we have the possibility to enter some line feeds or carriege return signs. In the preview, you can see it in Odoo, but on the pdf generation, the signs are ignored. 


What i tried is:

<t t-set="temp_name" t-value="temp_name.replace('\n','&#13;')"/>

<t t-esc="temp_name"/>

but this produces an exception:



  File "/home/odoo/src/odoo/9.0/openerp/tools/safe_eval.py", line 296, in safe_eval
    c = test_expr(expr, _SAFE_OPCODES, mode=mode)
  File "/home/odoo/src/odoo/9.0/openerp/tools/safe_eval.py", line 153, in test_expr
    code_obj = compile(expr, "", mode)
QWebException: EOL while scanning string literal (, line 1)
头像
丢弃
2 答案
2
Avatar
Ray Carnes
Best Answer

Have you seen and tried https://www.odoo.com/forum/help-1/question/webkit-line-returns-for-text-fields-11072 ?

-------------------------------------------------------------------------------------


${note | carriage_returns} is what you looking for

with:

    

at the start of the document

1 备注
头像
丢弃
Avatar
Andreas Jonderko
-

Thank you very much, I tried this, but get also an exception on inserting the definition. Where exactly can I put this definition?

0
Avatar
quincybatten
Best Answer

An EOL ( End of Line ) while scanning string literal error indicates that the Python interpreter expected a particular character or set of characters to have occurred in a specific line of code, but that those characters were not found before the end of the line . This results in Python stopping the program execution and throwing a syntax error . Reasons:

  • Missing quotes

  • Strings spanning multiple lines

Strings can't normally span multiple lines. If you don't want the string to appear on multiple lines but you want to initialize it on multiple lines (so you can read it more easily), you can "escape" the newline by putting a backslash before the newline. If you want it to appear on multiple lines, you can use triple quotes around the string. Python is particularly prone to this type of error, since Python ends statements with newlines/line breaks , whereas most other programming languages have a character such as a semicolon (:wink: , which means that other programming languages work more easily with multi-line statements out of the box.

http://net-informations.com/python/err/eol.htm

头像
丢弃