Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Can we apply seperate color to partilcular column in Tree View?

By
vadivel
on 5/14/15, 4:03 AM 1,749 views

Dear Friends,

I am in a situation to change the colour of particular column's. In accounting for chart of accounts if balance is in negative(-) i have to show it in red colour for that particular account(Note: balance column only to be shown in red colour). So please reply if anyone knows if it is possible.Thanks in advance.

8

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 5/14/15, 9:17 AM

Yes, it's possible using custom widget and quite simple.

you'll need to write your widget in javascript lets say with a name: "my_widget" 


under static/src/js/ folder in your module add javascript file with a custom widget (say static/src/js/mywidget.js):

 openerp.your_module_name = function (instance) {
    instance.web.list.columns.add('field.your_widget_name', 'instance.your_module_name.your_widget_name');
    instance.your_module_name.your_widget_name = instance.web.list.Column.extend({
        _format: function (row_data, options) {
            res = this._super.apply(this, arguments);
            var amount = parseFloat(res);
            if (amount < 0){
                return "<font color='#ff0000'>"+(-amount)+"</font>";
            }
            return res
        }
    });
//
//here you can add more widgets if you need, as above...
// };

the above example widget can be used in a list view for field of type float and it displays a content in red if value < 0, also "hides" '-' sign. adapt it to your requirements.


don't forget to add javascript file to your module:

in v7.0 through __openerp__.py manifest:

'js':['static/src/js/mywidget.js'], 

in v8.0 through XML file:

  <template id="assets_backend" name="your_module_name assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/your_module_name/static/src/js/mywidget.js"></script>
</xpath> </template>



then in your tree view, use this widget for the column you need to apply your rules to:

<tree >
    ....
    <field name="field_name" widget="my_widget"/>
    ....
</tree>


do not forget to add 'web' as dependency in __openerp__.py:

'depends': ['web',....]

that's it.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/14/15, 4:03 AM
Seen: 1749 times
Last updated: 8/19/15, 2:56 PM