Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display warning message in Odoo-11?

I am using Odoo 11 and I want to display a Warning popup in a @api.constraint method. The warning popup that I want to display has two buttons, the first is an OK button used to ignore the warning and the other one is a Cancel button used to attempt the saving operation, it' s similar to the warning popup that odoo uses like on the picture below : The warning message that i want to display is similar to this one

I searched a lot on the web and I found different proposed solutions like using Wizard, exception.Warning() and osv.except_osv(), but unfortunately no one of this solution gives me exactly what I want.

Any help please?

like image 736
LALMI Mohamed Lamine Avatar asked Jan 28 '23 10:01

LALMI Mohamed Lamine


1 Answers

You can raise warning message by different ways. I have created message related to stock quantity by this way:

if self.qty > new_qty:
       message = _('You plan to sell %s quantity but you only have %s available in %s warehouse.') % \
                     (self.qty, self.product_id.virtual_available, self.order_id.warehouse_id.name)
       mess= {
                    'title': _('Not enough inventory!'),
                    'message' : message
                }
       return {'warning': mess}

This return same wizard of warning as you want and as shown given image.

like image 134
Keval Mehta Avatar answered Jan 31 '23 01:01

Keval Mehta