Reputation: 153
I want to show a warning message in user interface side in my module in a particular condition.For that I have write the code like this.
raise osv.except_osv(('Warning!'), ("Entered Quantity is greater than quantity on source."))
But in that condition in user interface side it just showing the loading image.
At the console I got the error like this.
2013-06-10 09:45:53,612 364
ERROR None openerp.netsvc: Warning! Entered Quantity is greater than quantity on source.
Traceback (most recent call last):
File "C:\OpenErp\openerp\openobject-server\openerp\netsvc.py", line 361, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "C:\OpenErp\openerp\openobject-server\openerp\service\web_services.py", line 585, in dispatch
res = fn(db, uid, *params)
File "C:\OpenErp\openerp\openobject-server\openerp\osv\osv.py", line 167, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "C:\OpenErp\openerp\openobject-server\openerp\osv\osv.py", line 121, in wrapper
return f(self, dbname, *args, **kwargs)
File "C:\OpenErp\openerp\openobject-server\openerp\osv\osv.py", line 176, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "C:\OpenErp\openerp\openobject-server\openerp\osv\osv.py", line 164, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "C:\OpenErp\openerp\openobject-addons\mat_mgmt\mat_mgmt.py", line 101, in button_confirm
raise osv.except_osv(('Warning!'), ("Entered Quantity is greater than quantity on source."))
except_osv:
('Warning!', 'Entered Quantity is greater than quantity on source.')
c:\openerp\openerp\openobject-addons\mat_mgmt\mat_mgmt.py(101)button_confirm()
-> raise osv.except_osv(('Warning!'), ("Entered Quantity is greater than quantity on source."))
I want to show the warning message on user interface side.
Upvotes: 0
Views: 4092
Reputation: 3822
I faced the same probleme and I resolved by :
from odoo import models, fields, api, _, osv # here add osv
raise osv.osv.except_osv(('Warning!'), ("Entered Quantity is greater than quantity on source.")) # here replace osv by osv.osv
I did this b-coz you will find the finction in odoo/osv/osv.py file
Upvotes: 0
Reputation: 206
If you just want to display a warning message, you might look at using the action_warn
client action. You invoke it by returning a dictionary like this one from your server action:
{
'type': 'ir.actions.client',
'tag': 'action_warn',
'name': 'Warning',
'params': {
'title': 'Warning!',
'text': 'Entered Quantity is greater than quantity on source.',
'sticky': True
}
}
This may be more genteel than you're looking for, though, if you want something that will actually stop a form submission. It displays a Growl-like notification in the user's browser. But if all you want to do is give the user some feedback in the form of a notification, either this or action_info
(invoked the same way as action_warn
) should do nicely.
I've got a fuller example up on my blog, but hopefully this is enough to get you going in the right direction.
Upvotes: 0
Reputation: 1216
Can you check with below code
raise osv.except_osv('Warning!', "Entered Quantity is greater than quantity on source.")
If you need translated messages then try _('meesage....')
But do not miss to import statement
from openerp.tools.translate import _
Upvotes: -1
Reputation: 73
First you need to import
from openerp.tools.translate import _
then, you can get the job done!
raise osv.except_osv(_(u'TitleMessage'), _(u'BodyMessage'))
Upvotes: 2