警告消息不在openerp上工作

时间:2013-06-10 05:10:46

标签: python-2.7 openerp

我希望在特定条件下在模块的用户界面侧显示警告消息。为此,我编写了这样的代码。

raise osv.except_osv(('Warning!'), ("Entered Quantity is greater than quantity on source."))

但在用户界面方面,只显示加载图像。

在控制台我得到了这样的错误。

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."))

我想在用户界面显示警告消息。

4 个答案:

答案 0 :(得分:2)

首先你需要导入

from openerp.tools.translate import _

然后,你可以完成工作!

raise osv.except_osv(_(u'TitleMessage'), _(u'BodyMessage'))

答案 1 :(得分:0)

如果您只想显示警告消息,可以查看使用action_warn客户端操作。您可以通过从服务器操作返回类似这样的字典来调用它:

{
    'type': 'ir.actions.client',
    'tag': 'action_warn',
    'name': 'Warning',
    'params': {
       'title': 'Warning!',
       'text': 'Entered Quantity is greater than quantity on source.',
       'sticky': True
    }
}

但是,如果你想要一些实际上会停止表单提交的东西,那么这可能比你正在寻找的更为温文尔雅。它在用户的浏览器中显示类似Growl的通知。但是,如果您要做的只是以通知的形式向用户提供一些反馈,那么这个或action_info(与action_warn调用的方式相同)应该很好。

我有一个更全面的例子up on my blog,但希望这足以让你朝着正确的方向前进。

答案 2 :(得分:0)

我遇到了同样的问题,我解决了:

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

我做了这个b-coz你会在odoo / osv / osv.py文件中找到结果

答案 3 :(得分:-1)

您可以查看以下代码

raise osv.except_osv('Warning!', "Entered Quantity is greater than quantity on source.")

如果您需要翻译的消息,请尝试_('meesage ....')

但不要错过导入声明

from openerp.tools.translate import _