URL Actions in Odoo

Abid Patel
26-Oct-2024 Updated : 26-Oct-2024

Learn to create URL actions in Odoo to open specific links and records directly from the interface. Improve navigation with URL actions.

URL Actions in Odoo

In Odoo, URL actions provide a way to navigate users directly to specific URLs from within the application. This feature is helpful for opening internal or external links, allowing users to access external resources, web pages, or specific Odoo records seamlessly.

Creating a URL Action in Python

To define a URL action, you return a dictionary specifying the URL and action type. Here’s an example:

python
def action_open_record(self):
    return {
        'type': 'ir.actions.act_url',
        'url': '/web#id=%s&view_type=form&model=custom.model' % self.id,
        'target': 'self'
    }

In this example:

  • type: Specifies the action type as 'ir.actions.act_url', telling Odoo to open a URL.
  • url: Points to the web client URL, where self.id dynamically injects the record ID.
  • target: Defines where the URL opens. Use 'new' for a new tab or 'self' for the same tab.

Adding a Button in the XML View

To make this action accessible, you can add a button in your view XML file:

xml
<button name="action_open_record" type="object" string="Open Record" class="btn-primary"/>

This button triggers the action_open_record method, which opens the form view of the specific record in the same tab. Add this button to the desired view to make it available to users.

Conclusion

By implementing URL actions in Odoo, you can streamline navigation within the system and link users directly to necessary pages, both within and outside of Odoo. URL actions provide an efficient way to enhance the user experience by making information and resources easily accessible.

Make a Comment

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