How to Open a Success Message Popup in Odoo

Odoo doesn’t support popup messages out of the box. There is this raise Warning(message) which opens a popup to show errors. However, you SHOULD never use them to show messages to users.

In Odoo, everything runs inside a big transaction. When there is a raised exception, Odoo will carry out a rollback in the database for all committed transactions. So it is not recommended to use this approach to show informational or success messages.

Our correct approach is to use a wizard.

Wizard class

class MyModuleMessageWizard(models.TransientModel):
    _name = 'mymodule.message.wizard'
    _description = "Show Message"

    message = fields.Text('Message', required=True)

    @api.multi
    def action_close(self):
        return {'type': 'ir.actions.act_window_close'}

View

<!--Message Wizard -->
<record id="mymodule_message_wizard_form" model="ir.ui.view">
    <field name="name">mymodule.message.wizard.form</field>
    <field name="model">mymodule.message.wizard</field>
    <field name="arch" type="xml">
        <form>
            <field name="message" readonly="True"/>
            <footer>
                <button name="action_close" string="Ok" type="object" default_focus="1" class="oe_highlight"/>
            </footer>
        </form>
    </field>
</record>

Then call the wizard from any actions.

@api.multi
def mymodule_open_popup(self):
    mymodule = self.get_server_info(self.name)
    
    message_id = self.env['mymodule.message.wizard'].create({'message': 'Your action was completed.'})
    return {
        'name': 'Message',
        'type': 'ir.actions.act_window',
        'view_mode': 'form',
        'res_model': 'mymodule.message.wizard',
        'res_id': message_id.id,
        'target': 'new'
    }

2 thoughts on “How to Open a Success Message Popup in Odoo”

    1. @api.multi is considcered as default behaviour since Odoo 13, so you don’t need the @api.multi decoration, just strating from the method.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close