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

Hello everyone,

I have a simple kanban view on Odoo 12 and I need to change the color of a specific field shown on kanban based on another field value on the same model.

In fact, I don't even know how to change kanban colors for both fields and background.

On my model I have:

odometer = fields.Integer('Odometer Control')
limit_reached= fields.Boolean('Limit reached')

Both fields are shown on kanban view on the xml for the model and I need to change the "odometer" field color to red, if the "limit_reached" value is true.

Alternatively, I can also change the full background color if "limit_reached" is true.

How can I achieve that on Odoo 12?

Thank you in advance

Regards

Avatar
Discard
Best Answer

Hello Paulo Matos,

Here is the example, In that if limit_reached is true then color will be changed to green.

Example :-

<record id="kanban_view" model="ir.ui.view">
    <field name="name">model.model.kanban.view</field>
    <field name="model">model.model</field>
    <field name="arch" type="xml">
        <kanban class="o_kanban_small_column" create="false">
            <field name="limit_reached"/>
            <field name="name"/>
            <templates>
                <t t-name="kanban-box">
                    <div t-attf-class="oe_kanban_color_#{record.limit_reached.raw_value} oe_kanban_card oe_kanban_global_click">
                        <div class="oe_kanban_content">
                            <strong><field name="name"/></strong>
                        </div>
                    </div>
                </t>
            </templates>
        </kanban>
    </field>
</record>

Hope it will works for you.

Thanks,

Avatar
Discard
Author

Thank you very much @Jignesh Mehta

I have tried the code but I am having an "Expected Singleton" error.

Perhaps this is because the field "limit_reached" is obtained by a compute function and has the store value set to False.

I can try another solution that is comparing two values from 2 integer fields.

In this case, I have on my form 2 values:

- km = fields.Integer('KM')

- odometro = fields.Integer('Odometer')

Can you please help me change the above code to compare if "odometer" is bigger than "km"?

Thank you once again

Hello, When "Expected Singleton" occurs, you have to use loop in code. Try to add loop before line and then restart server.

Related Posts Replies Views Activity
1
Dec 20
1843
2
Mar 24
6127
1
Sep 22
6210
0
Nov 19
37
3
Oct 19
3353