How To Open The Form View Of Many2many Clicking Tag In Odoo 16

HARSHAD
August 1, 2023
to-open-the-form-view-of-many2many

CRM, sales, purchases, inventory, accounting, HR, manufacturing, and other business applications are available through the open-source enterprise resource planning system known as Odoo. For storing data in a database, Odoo provides a variety of field types, the many2many fields, which provide a variety of widgets, are one of them. Using the “many2many_tags” widget, a user can choose many entries to utilize as tags. In Odoo, we already have the option to modify a tag’s default color.

As a result, we will now learn how to click on a tag to open its form view. With the use of this functionality, we can easily connect a tag to get its form view. To do it, we must make a’many2many_tags_field.js’ file in the static/src/js directory.

odoo-many2many

The next step is to update and extend an existing OWL component. First, import all the required files.

update-and-extend-an-existing-owl-component

To expand it, we’re importing ‘Many2ManyTagsFieldColorEditable’ here. We import the patch because we are employing the patching procedure. Using the import ‘_t’, string translations are performed. To access services, import the ‘use service’ command. The Odoo web framework’s dialog module is imported by dialog.

The patching procedure is now finished by expanding the ‘Many2ManyTagsFieldColorEditable’ prototype in the’many2many_tags_field.js’ file. The function onBadgeClick() will then be overridden in order to open the form. The open dialog box function is overridden when many2many fields are clicked, and the open form view method opens the field’s form view when it is clicked.

open-dialog-box-function-is-overridden

many2many fields are clicked the original function is called by overriding the setup method, and the ‘action’ service is also initialized. In order to ensure that the parent class is executed before the current logic is used, the function “this._super.apply(this, arguments)” is used.

We create a dialog window with the following characteristics:

*Size: Indicates the size of the dialog box.

*Buttons: Shows every button in the dialog box. An open-form view button is added here.

*$content: Shows the contents of the dialog window.

The method that deals with button clicks calls this.action.doAction. The donation method receives a number of arguments, including.

The ‘ir.actions.act_window’ window opening action is displayed.

Represents the model that must be opened and is stored in “this.props.relations” (*res_model).

*Views: The form view is set here. We are opening the form, so the action works view.

*Target: The window that will open in the current tab is shown here. We are designating it with a present goal.

Here is an illustration of a user interface that demonstrates how this is done. Choose a many2many tag first. We are choosing taxes in the invoice in this situation. Additionally, we have labels for clients, tasks, and various form views.

odoo-many2many-tag-first
When we click this tag, a dialog box appears with the option to either open the form view or cancel it.
open-the-form-view-or-cancel-it

When we click the button to open the form in a new window, the form will show up as in the picture below.

odoo-form-view

In this manner, clicking the tags opens the many2many form view in Odoo.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *