RandomPerson
RandomPerson

Reputation: 790

Openerp show message dialog

How can I show a message box in openerp? I was using raise like this:

raise osv.except_osv(_("Warning!"), _("Error"))

But this stops executing other code, I only want to display an informative message box.

Upvotes: 4

Views: 3357

Answers (2)

gordian1983
gordian1983

Reputation: 38

One way comes to my mind... You can use some on_change method that would return dict like this:

return {
        'warning': {
              'title':'Message title!',
              'message':'Your message text goes here!'
               }
        }

Upvotes: 0

no coder
no coder

Reputation: 2290

Raising an osv.except_osv does a couple of things:

1) Interrupts the current processing (it is a python exception after all).

2) Causes OpenERP to roll back the current database transaction.

3) Causes OpenERP to display a dialog box to the user rather than dumping a stack trace and giving the user a "bad stuff happened" message.

For onchange we can return

warning = {
        'title': 'Warning!',
        'message' : 'Your message.'
    }
return {'warning': warning}

But it will not work for other things like button.

For your case you can do

cr.commit()  
raise osv.except_osv(_("Warning!"), _("Error"))

But calling cr.commit explicitly in business transaction will leads to severe issues.

The other way is you can return a wizard with warning message. This is what most people used.

return {
            'name': 'Provide your popup window name',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': [res and res[1] or False],
            'res_model': 'your.popup.model.name',
            'context': "{}",
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'res_id': record_id  or False,##please replace record_id and provide the id of the record to be opened 
        }

Upvotes: 2

Related Questions