Enable Dark Mode!
how-to-create-and-manage-handle-widget-for-kanban-view-in-odoo-17.jpg
By: Ameen F

How to Create & Manage Handle Widget for Kanban View in Odoo 17

Technical Odoo 17

The handle widget primarily allows users to move lines up or down. A frequently requested feature by customers is the ability to rearrange data in kanban and tree views. This widget is particularly effective in the kanban view. To use it, specify it as widget="handle."

What is the functionality of the Handle widget?

Odoo 17 includes various types of widgets, one of which is the handle widget. This widget is primarily used in views to rearrange records by dragging lines up or down, making the interface more user-friendly. It doesn’t delete records but allows for reordering, such as swapping the first record with the second. In tree views, a cross icon is displayed, enabling users to drag and reorder records. While the kanban view doesn’t show symbols, it still allows data order adjustments.

Creating Fields and Model

In this example, we will create a new custom model. Within the model, we need to define a sequence field of type integer. Additionally, we can specify any required fields as needed.

# -*- coding: utf-8 -*-
from odoo import models, fields
class HandleWidget(models.Model):
  _name = "handle.widget"
  _description = 'Handle'
  name = fields.Char(string="Name")
  image = fields.Binary(string="Image")
  sequence = fields.Integer(string="Sequence")

To rearrange or update the order of photos, a kanban view is required. This kanban view must be defined in XML, including a corresponding sequence field. The sequence, an integer field, needs to be specified in the XML view. By leveraging this sequence field, objects can be reordered or relocated. Typically, images are displayed as attachments based on the order they were uploaded. In such cases, this widget proves highly useful, as adjusting the order becomes convenient for users.

<record id="handle_kanban" model="ir.ui.view">
   <field name="name">handle.widget</field>
   <field name="model">handle.widget</field>
   <field name="arch" type="xml">
       <kanban>
           <field name="sequence" widget="handle" invisible="1"/>
           <field name="id"/>
           <field name="image" widget="image" class="oe_avatar"/>
           <templates>
               <t t-name="kanban-box">
                   <div>
                       <div t-attf-class="oe_kanban_global_click">
                           <b>
                               <div class="o_kanban_image" style="width: 100%;">
                                   <img t-att-src="kanban_image('handle.widget', 'image', record.id.raw_value)"
                                        alt="Image" style="width: 100%; height: 175px;"/>
                               </div>
                               <br/>
                           </b>
                       </div>
                   </div>
               </t>
           </templates>
       </kanban>
   </field>
</record>

OUTPUT :

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

To begin, an image must be uploaded, and the name of the corresponding file entered. Each file is assigned a unique name. If the user wishes to rename the file, the new name should be specified in the field provided for the file name. Once completed, the kanban view will appear as follows

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

Imagine adding two different photos. If the user wants to rearrange the records, a widget can simplify the process.

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

Records can be rearranged, as demonstrated in the example above. Similarly, the order of saved records can be modified. Once the records are swapped, the outcome should resemble the example shown below.

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

Handle widget for tree view

The handle widget is used to adjust the original order of records. While we have discussed its application in the kanban view, this section focuses on its use in the tree view. If a user needs records in a specific order, they can arrange them initially and then use the handle widget to modify the order as desired.

Create Tree view

<record id="handle_widget_tree" model="ir.ui.view">
   <field name="name">handle.widget</field>
   <field name="model">handle.widget</field>
   <field name="arch" type="xml">
       <tree>
           <field name="sequence" widget="handle"/>
           <field name="name"/>
           <field name="image" invisible="1"/>
       </tree>
   </field>
</record>

First, we need to have a tree view, as it is easier to use. To modify the order of records, simply drag and drop the records to rearrange them as needed.

OUTPUT :

To begin, we need to create a record. In this example,we will add two records. We can also adjust the order of the records created. must first create the record. In this example, we'll add two records. Here we can alter the order of the created records.

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

Here are the two records we created,If the user wants to rearrange the records they can simply drag and drop them.

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

Records can be rearranged, as demonstrated in the example above. Similarly, the order of saved records can be modified. Once the records are swapped, the outcome should resemble the example shown below.

How to Create & Manage Handle Widget for Kanban View in Odoo 17-cybrosys

Using the handle widget in Odoo17, we can manage the order of records in this way.

To read more about How to Create & Manage Handle Widget for Kanban View in Odoo 16, refer to our blog How to Create & Manage Handle Widget for Kanban View in Odoo 16.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
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