Enable Dark Mode!
how-to-create-user-notification-odoo-13.png
By: Sayooj ao

How to Create User Notification in Odoo 13

Technical Odoo 13

In this blog, we can discuss how we can create user notifications in odoo. In odoo, we can notify the status of the specific actions by using different types of Exceptions and by changing the states of the required documents/records.


In some cases, odoo uses sticky notifications, the rainbow man effect, and alerts for informing the user.


The actions are notified by

    1. Sticky Notification

    2. Rainbow man

    3. Alerts

    5. Raising Exceptions in Odoo


Sticky Notifications

We can return sticky notifications in our function based on the conditions that we need.


By default, odoo has some sticky notifications.


how-to-create-user-notification-odoo-13


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


By using the python code

def your_custom_function(self): notification = { 'type': 'ir.actions.client', 'tag': 'display_notification', 'params': { 'title': _('Your Custom Title'), 'message': 'Your Custom Message', 'sticky': (True/False), } } return notification

For example 

def create_notification(self): message = { 'type': 'ir.actions.client', 'tag': 'display_notification', 'params': { 'title': _('Warning!'), 'message': 'You cannot do this action now', 'sticky': False, } } return message

The above code will generate a notification like below

how-to-create-user-notification-odoo-13


By using javascript function


We have two options in the case of javascript. The first one is the usual notification (do_notify) like the above one and the other is a warning (do_warning).

your_custom_function:function(){ this.do_notify("title","message","sticky","className"); }

title: Title of notification.

message: Message to display.

sticky: Boolean value (optional) if the true user must dismiss the notification.

className : CSS class (optional).

onclick_myicon:function(){ this.do_notify("Error","Please Check the values before save"); }

The above code will return


how-to-create-user-notification-odoo-13
onclick_myicon:function(){ this.do_warning("Error","Please check the values before save",false); }

The above code will return the following


how-to-create-user-notification-odoo-13


The next one is the rainbow man effect. We can see a rainbow man effect in default odoo while doing reconciliation.


how-to-create-user-notification-odoo-13


You can add this feature to your function by simply adding the following code

def action_approve(self):


"""This is the approve function which changes the state to running""" self.sudo().write({ 'state': 'running' }) return { 'effect': { 'fadeout': 'slow', 'message': 'Enter your custom message here', 'type': 'rainbow_man', } }


The above function will return a rainbow man with a custom message. fadeout can be slow, fast, and no. 


The next one is Alerts we can create different alerts for our specific conditions and actions in our form view.


For example


how-to-create-user-notification-odoo-13


This is from the invoice which appears when there are outstanding payments.

We can send these types of notifications to our custom modules for particular conditions.


Example:

<xpath expr="//sheet" position="before"> <div class="alert alert-danger" role="alert" style="margin-bottom:0px;" attrs="{'invisible': [('state', '!=', 'sale')]}"> This is from the sales team <bold> <a class="alert-link" role="button"> <field name="team_id" readonly="True"/> </a> </bold> </div> </xpath>
how-to-create-user-notification-odoo-13


We can either add to the existing models or the custom models which we created. The above code indicates the addition of the notification to an existing model(sale. order).

In that case, we have to use XPath for adding the notification.


Actually, this notification contains a div. If we want to redirect to any other forms we can include it in that div with a tag with the field related to the required form. In the above example, we can redirect to the sales team of the corresponding sales order. We can assign different classes to the div for changing its look and appearance (alert alert-info, alert alert-warning, alert alert-danger, etc..)


If you need any assistance in odoo, we are online, please chat with us.



2
Comments

It is not working with website page.If i'm passing this as a return in a method,then it does not show anything.

27/04/2020

-

11:54PM

Sabyrzhan

For web site, may be you should to use Java Script custom?

09/07/2020

-

10:09PM



Leave a comment

 


whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message