Thursday, October 19, 2023

Remove xml entities from html field value in odoo

In this blog we will explain how to remove xml entities from html field value in odoo and to make it clear let us give an example 

We created new task in the project module , and this task has description as in the image bellow 

 

and we created custom task portal view , but when we try to view the task description it displayed with some tags and we need to remove them .. just as in the image bellow
 

so to fix this bug we can add new function inside the controller and this function take the description field value as an input and return the clean text of the description without tags , so the function can be as bellow 

def clean_text(self,html_field_value):
        clean = re.compile(r'<[^>]+>')
        clean_text =  re.sub(clean, '', html_field_value)
        return clean_text

#Note : we must import re package first as "import re"

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...