Skip to content

Instantly share code, notes, and snippets.

@Amr-Nash
Last active October 6, 2022 12:12
Show Gist options
  • Save Amr-Nash/e3ce96776478c126eac9e0c695c5ddf2 to your computer and use it in GitHub Desktop.
Save Amr-Nash/e3ce96776478c126eac9e0c695c5ddf2 to your computer and use it in GitHub Desktop.
Two ways of showing a notification on Odoo

1. Showing a notification with @onchange functionality:

@onchange('some_field')
def onchange_some_field(self):
  return {
          'warning': {'title': "Warning", 'message': "What is this?", 'type': 'notification'},
      }

please notice that if you skip the:

'type': 'notification'
it would return a pop-up like UserError message that would require you to press ok

2. Showing a notification with the press of a button:

def action_button(self):
return {
          'type': 'ir.actions.client',
          'tag': 'display_notification',
          'params': {
              'type': 'success',                 # you can change this to get defferent colors with 'error' or 'warning'
              'title': _("Notification Title"),
              'message': 'Notification message',
              'next': {
                  'type': 'ir.actions.act_window_close'
              },
          }
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment