The handle widget is mainly used for dragging the line up and down. It is mainly used for replacing the order of records in the view. There are mostly two types where handle widget is used in the cases of kanban and tree view. Changing the order of kanban and tree records is one of the most sought-after features by users. The widget is mainly applicable in the kanban view. The handle is a widget that is simply defined like widget=” handle.”
This blog goes into detail about the video preview widget in Odoo.
1. Why exactly is the Handle widget used in Odoo?
2. Handle widget for kanban view
3. Handle widget for tree view
What is the purpose of the Handle widget?
There are various types of widgets in Odoo. Handle widget is one among them. It is mainly used inside the views. It will help us to reorder according to the sequence. It will help to change the order and make it easy to use. It will not remove a record, only it will drag lines up and down. In some cases, we have to make the first record to be second and the second to be first. In such cases, we have to use this widget. In the case of the tree view, there, a cross sign will be visible. By dragging that, we can rearrange the order of the records. Please note that while there will be no symbols for the kanban view, we can change the order of the records all the same.
Handle widget for kanban view
The purpose of the handle widget is to change the order of the specified records. If suppose the user needs a specified order, then the user can create in some order, and then with the help handle widget, it can be replaced. Making it some specified order is also possible with the help of this widget.
Creating Fields and Models
In the following example, we are going to create a new custom model. Over there, we have to specify a sequence field with a type of integer. And also, we can specify the necessary fields.
class Handle(models.Model):
_name = "handle.kanban"
_description = 'Handle'
image = fields.Binary(string = "Image")
sequence = fields.Integer(string = "Sequence")
Create a kanban view
Initially, we need a kanban view in order to make changes or replace the order of the images. Hence we have to define the kanban view in XML. Inside the kanban view, we have to specify a corresponding sequence. The sequence should be an Integer field, and it should be specified in the XML view. With the help of this sequence field, we can make the movements or exchange the specified order. In general, images are shown according to the uploaded order into the ir.attachment as a new attachment. In such cases, we can use this widget and it is very helpful for a user to swap the order.
<record id="handle_kanban" model="ir.ui.view">
<field name="name">handle.kanban</field>
<field name="model">handle.kanban</field>
<field name="arch" type="xml">
<kanban>
<field name="sequence" widget="handle" invisible="1" />
<field name="id" />
<field name="image" />
<templates>
<t t-name="kanban-box">
<div style="width: 150px; height: 185px;">
<div t-attf-class="oe_kanban_global_click">
<b>
<div style="font-size:20px;" class="o_kanban_image_fill_top">
<img t-att-src="kanban_image('handle.kanban','image', record.id.raw_value)"
style="width:100%; height:166px;" />
</div>
<br />
</b>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
OUTPUT:
First of all, we have to upload an image, and also, we have to specify the corresponding file name. Each file has its own name. If the user wants to give another name to the file, it should be given over the filed file name. After that, the kanban view will be like this:
For example, add three odoo log images in different colors. Suppose the user needs to be exchange the order of the records means images, then it will be possible with the help of a widget.
Like the above example, we can replace the images. And also change the order of the records that have been saved. After exchanging the images, the output should be like the given below.
Handle widget for tree view
The purpose of the handle widget is to change the order of the specified records. We have discussed the widget for kanban view. Here we are going to discuss the widget for tree view. If suppose the user needs a specified order, then the user can create in some order and then with the help of handle widget, it can be replaced and make it some specified order is also possible.
Create Tree view
Initially, we need a tree view. It is easier to use. There will be a symbol in the tree view in order to change the order of the records. Inside the tree view, we have to specify a sequence. With the help of that sequence, we can change the order of the records and swap the records.
<record id="handle_kanban_tree" model="ir.ui.view">
<field name="name">handle.kanban</field>
<field name="model">handle.kanban</field>
<field name="arch" type="xml">
<tree default_order='sequence'>
<field name="sequence" widget="handle" />
<field name="id" invisible="1" />
<field name="image" invisible="1" />
<field name="file_name_new" />
</tree>
</field>
</record>
OUTPUT:
Initially, we will have to upload the image that must be uploaded. In this example, we are going to add three files with the names FILE1, FILE2, and FILE3. Besides the file name, there will be a symbol that indicates that we can change the order of the records that have been created. That symbol will be shown whenever this handle widget is used. After adding the files, the tree view should be like the one given below:
Suppose the user needs to swap the records in a tree view, hold that symbol and replace it. It is very easy to use. Just hold the symbol and swap according to the wish of the user.
So here we are going to change the order as FILE2 with FILE1. Swapping FILE2 with FILE1. And the final result should be like this:
Watch our video for reference on the Handle widget