User Alerts and Notification in Odoo

HARSHAD
August 18, 2022

There are certain cases where it is ideal to show ‘notifications’ or ‘alerts’ on-screen rather than emails or personal messages being sent to the users. In this blog, we will discuss the various ‘notifications’ or ‘alerts’ that can displayed on the screen to the user because of some actions. There are different types or categories of notification in Odoo, that can use according to one’s requirements. And In Odoo, it can mainly notify Users by using the following notifications –

1. Sticky Notification
2. Rainbow man
3. Alerts
4. Raising Exceptions in Odoo

1. STICKY NOTIFICATION IN ODOO

Someone mostly displayed this type of notification on the right- side of the screen. We can return sticky notifications in our function based on the conditions that we require.

By default, Odoo uses some sticky notifications to alert its users.

For example – if any user cannot enter the mandatory fields, a sticky notification in Odoo is displayed.

sticky-notification

We can also create this type of notification in our custom modules using python and JavaScript functions.

A. Using Python Functions

Parameters that are required to display the sticky notification are –
i. title: Title of notification.
ii. message: Message to be displayed.
iii. sticky: Boolean value (optional). if it is true, then the user must dismiss the notification.
iv. Example –

python-functions

Code will generate a notification in Odoo as shown below.

B. Using JavaScript

With JavaScript, there are two options – usual notification (do_notify) and warning (do_warning).
a. do_notify
Parameters that are required to display the sticky notification are –
i. title: Title of notification.
ii. message: Message to display.
iii. sticky: Boolean value (optional) if the true user must dismiss the notification.
iv. className : CSS class (optional).

do-notify

v. Example –

generate notification in odoo

The above code will generate a notification as shown below.

do-warning

b. do_warning
i. Example

notifications-in-odoo

Here the above code will generate a notification as shown below.

cod-will-generate

2. RAINBOW MAN EFFECT

The rainbow man effect is another type of attractive notification present in Odoo. By default, we can see the rainbow man effect while doing reconciliation.
You can also add a rainbow man effect to your custom modules, by adding the following code.

custom-modules

After clicking on the ‘Confirm’ button on the sale order, the above function will return a rainbow man with the message “Sale order  confirmed.”.
Here fadeout can be ‘slow’, ‘fast’, or ‘no’ for the rainbow man effect.

rainbowman-effect

3. ALERTS

This is another type of notification that can display messages as required.
By default, we can see this type of notification on invoices when there are outstanding payments for the customer.

display-messeges

We can also add these types of notifications to our custom modules or existing modules.
Example –

types-of-notifications

Code will generate an alert on the sale order form view as shown below.

generate-an-alert

We can define these types of notifications inside ‘div’ in XML files. If we want to redirect to another form, we can also specify the related field inside that div. The sales order mentioned in the notification can be redirecte in the example given above. Also, we can give different classes (alert-warning, alert-danger, alert-info, etc) to the div to give them different looks and appearances depending on the requirement.

4. RAISING EXCEPTIONS

Apart from displaying the notification messages, this type of notification is used to prevent the program from continuing its execution. This helps to prevent incorrect data entry into databases.
Example

validation-eror

The above code will raise a validation error when a user tries to delete the records which are not in the ‘Draft’ state.

something-went-wrong

Request Your Free Quote

"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 *