Display Sticky Notifications in Odoo for Important Alerts

Abid Patel
31-Oct-2024 Updated : 31-Oct-2024

Learn how to display sticky notifications in Odoo to keep important messages visible for users. This guide explains the setup and code to add alerts in Odoo.

Display Sticky Notifications in Odoo for Important Alerts

In Odoo notifications can enrich user experience. This is especially true after specific actions. Feedback is required. Users need alerts. Sticky notifications represent an effective strategy. They keep the message on-screen until it is dismissed. This guide delves into sticky notifications. We explore how to return an action with a sticky notification in Odoo. This ensures that users receive persistent critical messages. The messages display on their screens.

What is Sticky Notification

A sticky notification is a kind of notification. It stays visible on screen until user closes it manually. In Odoo notifications can be set as sticky. This makes them perfect for showing must-not-miss details.

Example Code: Action with Sticky Notification

Here's example. It shows usage of sticky notification in Odoo action. It sends a message to user. This message stays on screen until it’s closed manually.

python

from odoo import models, _

class CustomModel(models.Model):
    _name = 'custom.model'

    def action_show_sticky_notification(self):
        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'title': _('Attention'),
                'message': _("This is an important sticky notification."),
                'type': 'warning',  # Options: 'info', 'warning', 'danger'
                'sticky': True,     # Set to True to make the notification sticky
            }
        }
  • Return Dictionary: Return statement offers Odoo action dictionary. It determines what should occur next. This testifies a client action.
  • Type of Action: ir.actions.client is for client-side actions. It uses tag field with display_notification. This triggers notification.
  • Notification Parameters:
  • title: Sets title of notification. It is "Attention" in this case.
  • message: The message that appears in notification.
  • type: Defines notification's style. It can be info, warning or danger.
  • sticky: When set to True notification becomes sticky. It will not go away until user closes it.

When to Use Sticky Notifications

Sticky notifications prove being useful in certain scenarios. A description follows:

  • ▹ - An operation. It needs user confirmation or awareness.
  • ▹ - Critical information. It should be acknowledged by user.
  • ▹ - Alerts. They are needed for specific settings, configurations or missing data.

Example Use Case

A scenario is imagined. An Odoo administrator has to inform users. Users need to set settings in a module properly. A sticky notification is implemented. It ensures that alert will stay. This is until user acts. In this way, nothing is missed.

Utilize sticky notifications in Odoo. This is for the communication of vital messages. These messages need attention. Improve functionality. Improve usability of Odoo applications. This approach ensures user is informed. It guides them to necessary actions. The action is directly on their screen.

Make a Comment

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