I want to set the first line of the product description inside the printed PDF report of an Flectra/Odoo offer to BOLD so I added the following code to my model
@api.multi
def setFirstLineBold(self,txt):
txt = txt.replace('\n', '<br/>')
return txt
@api.multi
def render_html(self, docids, data=None):
report = self.env['report']._get_report_from_name(self._template)
docargs = {
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self.env['sale.order'].browse(self._ids),
'setFirstLineBold': self.setFirstLineBold
}
return report_obj.render(self._template, docargs)
I then called the method inside my template
<t t-foreach="layout_category['lines']" t-as="l">
<tr class="table-body">
<span t-esc="doc.setFirstLineBold(l.name)"/></td>
But what happens then is actually exactly the opposite of what I want to achieve: The formatting that previously existed in the description text (the line breaks), which were previously shown with line breaks in the printed pdf-report, has been completely removed. The HTML-linebreaks <br/>
are also printed instead of interpreted.
If I just run
@api.multi
def setFirstLineBold(self,txt):
return txt
all linebreaks in the text ('\n'
) seem to be removed or not interpreted, too. The text displays in one ugly block...
Now my question: How can I create formatting for the description text? I just want to make the first line bold.
thnx!
Using RAW instead of ESC solves the problem:
<span t-raw="doc.setFirstLineBold(l.name)"/>
https://www.odoo.com/forum/help-1/what-is-the-difference-between-t-esc-and-t-raw-92184