Development Book V17:Manage kanban stages

The Odoo Kanban view offers a straightforward and user-friendly approach for managing workflows. This view organizes records into columns, each representing a different stage of the process. Within each stage, records are listed, allowing for efficient movement between stages.

Similar to the definition of form view and tree view, we have to mention the view type of kanban view in action. This can be added as follows;


 <record id="action_mobile_service" model="ir.actions.act_window">
    <field name="name">Mobile Service</field>
    <field name="res_model">mobile.service</field>
    <field name="view_mode">tree,kanban,form</field>
    <field name="help" type="html">
        <p class="o_view_nocontent_smiling_face">
            Add a new analytic account
        </p>
    </field>
 </record>

Now the view definition will be like this;


    <record id="service_request_view_kanban" model="ir.ui.view">
    <field name="name">mobile.service.kanban</field>
    <field name="model">mobile.service</field>
    <field name="arch" type="xml">
        <kanban default_group_by="service_state">
            <field name="service_state"/>
            <templates>
                <t t-name="kanban-box">
                    <div class="oe_kanban_global_click">
                        <div class="oe_kanban_content">
                            <div class="oe_kanban_card">
                                <div>
                                    <b>
                                        <field name="name"/>
                                    </b>
                                </div>
                                <div class="text-muted">
                                    <field name="partner_id" widget="res_partner_many2one"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </t>
            </templates>
        </kanban>
    </field>
</record>

This is a basic kanban view definition. Apart from this, more classes and attributes are available to enhance it.

As mentioned above, the kanban view contains records in a card along with their states. Kanban states are really useful, and the records of each state will be draggable. For showing the states in the kanban view, we have to use the attribute ‘group_expand.’ By using this attribute on the field declaration, the kanban view will display the states even though no records are available on the state. So let’s set how it’s defined;

                          
service_state = fields.Selection([('draft', 'Draft'),
       ('assigned', 'Assigned'),
       ('completed', 'Completed'), 
       ('returned', 'Returned'),
        ('not_solved', 'Not solved')],
   string='Service Status', 
  group_expand='_group_expand_states',
 default='draft', 
 track_visibility='always')

As you can see, the attribute group_expand contains a function named ‘_group_expand_states.’ It’s defined as follows;


                            def _group_expand_states(self, states, domain, order):
   return [key for key, val in type(self).service_state.selection]

This function returns a list of states; thus, here, the function tries to pass all the selection fields in the list form to the method ‘group_expand.’ In the XML, the state field is defined as a normal field definition; here, we have defined it in the above example.

After following these things, the kanban view and its states will be as given below.

odoo-development

Progress bar in kanban view

Progress bar is another feature of the kanban view. Sometimes it is difficult to understand the states if the records are huge in number. Here the progress bar will help show each state's status on top of it. Let’s check how it’s defined; Here, as an example, the progress bar is based on the field priority;


  priority = fields.Selection([('0', 'Normal'),('1', 'Low'),
    ('2',   'High'),('3', 'Very High')],  
string="Priority")

Three attributes are used in the progress bar; they are field, colors and sum_field.

Field: The progress bar is shown based on the value of this field.

Colors: Mainly, there are four colors to assign to the values of the field. They are a success, warning, danger, and info.

Sum_field: This is an optional field for displaying the sum of any field in the record.

The progress bar is defined in the XML using the tag .


  < progressbar field="priority" colors='{"3": "success", 
 "2": "warning", "1": "danger", "0": "info"}'/>

Once the module is upgraded after adding the progress bar the kanban view will look like this;

odoo-development

While placing the mouse over the progress bar you can see the records belong to this field and the total number of the records will be displayed right to the column. This is by default, and if you want to show the sum of a particular field in a record, then it can be achieved by the attribute ‘sum_field’, but this is optional.

whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message