Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display html in tree view odoo

Is it possible display html in tree view?

For example add strong to string < strong >MY STRING < / strong >

I'm try use widget="html" but strong tag is visible!

.py

 @api.depends('name')
 def _get_html(self):
     self.html_text = "<strong>" + str(self.name) + "</strong>"

     html_text = fields.Char(compute='_get_html')

.xml

<field name="html_text"/>   
like image 923
user_odoo Avatar asked Jul 14 '17 11:07

user_odoo


1 Answers

To enable the HTML in list view you need to override the method _format() as below.(for Odoo v10)

JS

odoo.define('html_in_tree_field.web_ext', function (require) {
    "use strict";
    var Listview = require('web.ListView');
    var formats = require('web.formats');

    Listview.Column.include({
        _format: function (row_data, options) {
        // Removed _.escape() function to display html content.
        // Before : return _.escape(formats.format_value(row_data[this.id].value, this, options.value_if_empty));
        return formats.format_value(row_data[this.id].value, this, options.value_if_empty);
        }
    });
});

XML to add above JS.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="assets_ext" inherit_id="web.assets_backend">
      <xpath expr="." position="inside">
          <script type="text/javascript" src="/html_in_tree_field/static/src/js/web_ext.js"></script>
      </xpath>
    </template>
</odoo>

__manifest__.py

{
...
...
'data': [
        ...
        'views/above_xml_filename.xml',
    ],
....
}
like image 115
Emipro Technologies Pvt. Ltd. Avatar answered Oct 18 '22 03:10

Emipro Technologies Pvt. Ltd.