Search code examples
odoo

How to display a dialog with warning message from controller in Odoo?


Is it possible to display a warning message when overriding a controller function? This is the code I have:

raise Warning(_('Entered Quantity is greater than quantity on source.'))
return super(CheckCart, self).cart(**post)

I want to render the cart template but also raise a Warning, but I get the following:

500: Internal Server Error Error Error message: ('Entered Quantity is greater than quantity on source.', '')

Traceback

Without anything else.


Solution

  • Controller File.

    request.render("custom_module_name.redirect_fail_page", {})
    

    XML File.

    <template id="redirect_fail_page" name="Failure Code Page">
        <div>
              <span>Failed</span>
        </div>
        <script>
            setTimeout(function(){
                window.location.href = '/';
            }, 1100)
        </script>
    </template>
    

    Here you can use request.render