Skip to Content
मेन्यू
This question has been flagged
5 Replies
13174 Views

Hello everyone.
I have a model for which I need to set kanban box background color depending on the record "state".

The code is fine, but I cannot get the full kanban coloured background.

I am currently using Odoo 12 and found some samples for previous Odoo versions that's not working for this case.

On my py I have (besides other fields):

state = fields.Selection([('draft', 'New'),('to_start', 'Ready to Start'),('started', 'Started'),('confirm', 'Done')], string='Status', default='draft')
kanbancolor = fields.Integer('Color Index', compute="set_kanban_color")


    def set_kanban_color(self):
        for record in self:
            kanbancolor = 0
            if record.state == 'draft':
                kanbancolor = 1
            elif record.state == 'to_start':
                kanbancolor = 2
            elif record.state == 'started':
                kanbancolor = 3
            elif record.state == 'confirm':
                kanbancolor = 4
            else:
                kanbancolor=5
            record.kanbancolor = kanbancolor

On my xml file (only the kanban definition):

      <kanban class="o_kanban_small_column" create="false" default_order="id desc">
        <field name="name"/>
        <field name="brand"/>
        <field name="model"/>
        <field name="kanbancolor"/>
        <field name="state"/>
        <templates>
            <t t-name="kanban-box">
            <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.kanbancolor.raw_value)}">
                 <div class="oe_kanban_global_click">
                    <div class="oe_kanban_details">
                        <strong class="o_kanban_record_title">
                          <p class="oe_centeralign">
                            <field name="name"/>
                          </p>
                        </strong>
                        <ul><li class="oe_centeralign"><strong>Brand:</strong>&#160;<field name="brand"/>&#160; | &#160;
                            <strong>Model:</strong>&#160;<field name="model"></field></li></ul>
                    </div>
                </div>
            </div>
            </t>
        </templates>
      </kanban>

UPDATED: The code is running fine but instead of having the full background color, I only get a small bar at the left side of the kanban box.

How can I get a full background coloured kanban box?

Thank you all in advance

Avatar
Discard

Did find any solution on this?

Author

Hi @Nitin Kantak,

I did not find any solution for the "full background" color.

Thank you

PM

Best Answer

Hi Paulo Matos, try like this:


<kanban colors="blue:state=='draft';red:state in ('approve','confirm');black:state=='done'">
                    <field name="name" />

                    ....

 </kanban>

Avatar
Discard
Author

Hi @Jithin. Thank you very much.

I have tried to use your "template" code and was unable to achieve what I want.

I have tried (simplified):

<record id="mymodule_model_kanban_view" model="ir.ui.view">

<field name="name">View Name</field>

<field name="model">mymodule.model</field>

<field name="arch" type="xml">

<kanban colors="blue:state=='draft';red:state in ('to_start','started');black:state=='confirm'">

<templates>

<t t-name="kanban-box">

<field name="name"/>

</t>

</templates>

</kanban>

</field>

</record>

Can you please help me fix it?

Thanks once again

Best Answer

 

Avatar
Discard
Related Posts Replies Views Activity
1
अप्रैल 25
3949
1
जन॰ 25
2005
0
मार्च 24
1543
0
अक्तू॰ 22
2719
0
सित॰ 22
1965