Odoo 14 User Notification Creation Guide

The creation of user notifications in Odoo version 14 is covered in this blog. By utilizing several sorts of notifications, Odoo enables us to display the outcome of specific operations.

Notification Types

  1. Sticky Notifications
  2. Rainbow Man
  3. Alert
  4. Making Special Cases

Message Stickiness

Depending on the criteria we require, we can create sticky notifications for our functions in either the custom module or for pre-existing modules. Odoo employs certain sticky notifications by default. Both Python and JavaScript routines can be used to build sticky notifications.

Using Python Code

The output of the above function will produce the following notification:

{% raw %} 

from odoo import api, models, _ from odoo.exceptions import UserError 

class YourClass(models.Model): _name = 'your.model' 

@api.multi 

def your_method(self): 

    # Your logic 

    raise UserError(_('Your message here')) 

{% endraw %}

Using JavaScript

There are two possibilities when it comes to JavaScript:

do_notify

This will display a warning similar to the code above:

{% raw %} 

 

this.do_notify('Warning', 'Your message here'); {% endraw %}

do_warn

Used to display an alert message:

{% raw %} 

this.do_warn('Title', 'Your message here'); {% endraw %}

The notification’s title

Message that will appear in the notification

If the boolean value is true, the user must cancel the notification; otherwise, it is optional.

className: Specifies the optional CSS class.

The code above will result in:

Spectrum Man Effect

Another kind of notification in Odoo is the rainbow man effect. When reconciling, we automatically perceive the rainbow man effect. You may add a rainbow man effect to your custom modules by adding the following code:

function confirm_sale_order() { 

var message = 'Sale order confirmed.'; 

var man_effect = 'rainbow_man'; // quick, quick-and-no-rainbow-man 

var options = { 'message': message, 'title': man_effect, 'fadeout': 5000 }; 

return this.do_notify(man_effect, message, true, options); 

} 

When you click the confirm button on the sale order, the aforementioned function will return a rainbow guy with the message “sell order confirmed.” Here, the fadeout can be quick, quick-and-no-rainbow-man.

Alerts

Another notification type in Odoo is the alert. Depending on the circumstances and activities we require, we can generate various notifications.

As an illustration, here is the default warning that shows up when there are unpaid invoices.

Depending on our requirements, we can add various kinds of notifications to our bespoke modules.

As an illustration, we may add notifications to both already-existing models and to the unique models we developed. An illustration of adding a notification to an existing model is shown in the code above (sale.order).

In these circumstances, XPath must be used to add the notifications to the already existing models.

These notification types can be defined inside a div. We can specify the associated field to those needed forms inside that div if we wish to redirect to any other form. We can reroute to the sales order stated in the notification in the case above. To give the div multiple looks and appearances, we can assign it several classes (alert alert-warning,alert alert-danger,alert alert-info, etc.).

Bringing Up Exceptions

In Odoo, raising exceptions is used to stop the application from running further. We can achieve this by displaying error messages as a result of raising exceptions. All database data modifications are undone and operations are stopped when an exception is raised, avoiding inaccurate data entry into databases.

Hire Dedicated Developers

Reach new heights with WanBuffer’s offshore engineering team. Our team of over 50 highly skilled and dedicated full-stack software engineers have the expertise and experience to tackle your key technology challenges, improve efficiency and reduce expenses. Let us help you drive your business forward today.

Schedule Meeting