Skip to Content
Menu
This question has been flagged
1 Reply
2308 Views

I wanted to set the first line of the product description to BOLD so I added the following code to my model

@api.multi
    def setFirstLineBold(self,txt):
        # code magic to set first line bold
        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.

Now my question: How can I create formatting for the description text? I just want to make the first line bold.

It looks like the linebreaks will not be recognized as such or will be removed.
Unfortunately, the debugging seems impossible (not really, but extremly complicated) as I develop inside a docker container - I'm new to Odoo development, if someone gives me a tip here - thank you!


Thanks a lot!


EDIT: I already found out that this works:

@api.multi
def setFirstLineBold(self,txt):
    txt = txt.replace('\n', '<br/>')
    return txt
but the HTML is not interpreted, so it only shows <br/>
instead of ‘\n’ inside the description part of the PDF.

Avatar
Discard
Author

RAW works - thanx @Jainesh!

Best Answer

Hello @Headkit-games

Hope you are doing well,

We use <t t-esc="variable"/> when we want to parse a variable value.

but in your case, you have HTML in string format inside your variable/function so t-esc will just consider it as text.

If you want to print HTML after converting / parsing use <t t-raw="var_with_html"/>

You can take reference from ODOO documentation for Qweb or visit this link:

https://www.odoo.com/forum/help-1/what-is-the-difference-between-t-esc-and-t-raw-92184

Hope this solves your issue.

Thanks

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 19
7323
2
Jul 24
652
2
Mar 22
10544
1
Feb 24
10991
0
Nov 23
3245