OpenERP 弹出提示窗口小结OpenERP 弹出提示窗口有三种方式,详情可参考:http://www.cnblogs.com/cnshen/p/3205405.htmlhttp://shine-it.net/index.php?topic=2383.0这里注意讨论的是 raise osv.except_osv ()这种方式,效果图如下:1 ) 导入需要的模块from openerp.tools.translate import _from osv.osv import except_osv
2 ) 检查业务逻辑中的错误,终止代码执行,显示错误或警告信息在类方法中需要提示的地方加如下代码:raiseosv.except_osv(_('Error!'), _('Error Message.'))
注意:方法osv.except_osv()需要两个参数,把参数放在_()中是实现了参数的国际化,可以不加_() Eg:
def __assistant_depmanager_prove(self, cr, uid, ids, context=None): for qjd in self.browse(cr, uid, ids, context=context): if qjd.shenqr.user_id.id == uid: raise osv.except_osv(_('Warning!'), _('you cannot prove yourself')) return False elif qjd.tians > 1: raise osv.except_osv(_('Warning!'), _('There are not enough access ')) return False else: return True
翻译提示语#. module: qingjia
#: code:addons/qingjia/qingjia.py:0
#, python-formatmsgid "Warning!"msgstr "提示!"#. module: qingjia#: code:addons/qingjia/qingjia.py:0#, python-formatmsgid "you cannot prove yourself"msgstr "您不能审批您自己的请假单"
3) 在提示语中可以含有变量,以及对变量的中文翻译
def assistant_depmanager_proved_new(self, cr, uid, ids, context=None): res = self.browse(cr, uid, ids, context=context) result = res[0] raise osv.except_osv(_(' Error! '), _('Your uid is "%s" ,name is "%s",the state is "%s"')%(_(uid),_('王小波'),_(result.state))) result = self.__assistant_depmanager_prove(cr, uid, ids, context=context) if result: self.write(cr, uid, ids, {'state': 'proved'})
说明:这里的状态翻译后是对应的英文状态名,如果还需要翻译成中文,必须使用_()
#. module: qingjia#: code:addons/qingjia/qingjia.py:0#, python-format
msgid "Your uid is \"%s\" ,name is \"%s\",the state is \"%s\""
msgstr "你的用户id是:'%s',姓名是:'%s',请假单状态是:'%s'"
对定义的所有状态进行翻译,最后状态也将是中文的
#. module: qingjia
#: code:addons/qingjia/qingjia.py:0
#, python-format
msgid "wait_prove"msgstr "待批的"
效果图如下