TheoB
TheoB

Reputation: 11

Odoo - Show notification at the top right of the screen

Hello everyone (Sorry for my english)

I would like to be able to display a notification (pop-up type) at the top right of the screen.

In my case, projects view, this must occur when transferring a task from one stage to another in the Kanban view.

I saw some tutorials : https://www.cybrosys.com/blog/how-to-create-user-notification-odoo-13

https://developpaper.com/a-prompt-box-pops-up-in-the-upper-right-corner-of-odoo-13/

But they don't meet my need. In these examples, the "pop up" notification is called when a button is pressed. But I don't want to call the notification from a button, but from a function (but nothing happens)

I did like this:

def create_notification(self):
    return {
        'type': 'ir.actions.client',
        'tag': 'display_notification',
        'params': {
            'title': _('Warning!'),
            'message': 'My message',
            'sticky': False,
        }
    }


@api.onchange('stage_id')
def verification_changement_etape(self):
    ...blablabla...
    if self.type_temps.id:    # APPEL DE LA NOTIFICATION
        self.create_notification()

But nothing to do, the create_notification() function only seems to work when called from a button action.

If you can help me, that would be great!

(Or PLAN B: From my python code call my XML button which calls my notification) If someone can tell me how to call an XML button from python... On the internet I only find manipulation the other way around.

Edit :

Thank's for response. I don't want a blocking notification (forcing the user to click "ok" to close it). What I want is an informative notification, like the ones in the links above.

(Colored notifications)

The problem is that to make them appear, only calling the method from a button (click) seems to work. I can't make the call from my python code (in the write method for example)

Upvotes: 1

Views: 2300

Answers (3)

Cuong Huynh
Cuong Huynh

Reputation: 402

This solution worked for me

self.env["bus.bus"]._sendone(
            self.env.user.partner_id,
            "simple_notification",
            {
                "type": "success",
                "title": _("New Task Created Successfully"),
                "message": _('Your new task has been created.'),
                "sticky": True
                
            },
        )

Upvotes: 2

CG Drakwars
CG Drakwars

Reputation: 9

You need to return the result of create_notification

return self.create_notification()

Upvotes: 0

Scott
Scott

Reputation: 132

I had a similar need and solved it by modifying the write method of your custom module. This will show a popup when a user drags a kanban card from one stage to the next.

def write(self, vals):
    if 'stage_id' in vals:
        if vals['stage_id'] == 'xyz' and self.type_temps.id:    # APPEL DE LA NOTIFICATION: 
                raise UserError(_('Notification Popup'))
    return super(CustomModule, self).write(vals)

Upvotes: 1

Related Questions