OpenERP
彈出提示視窗小結
OpenERP
彈出提示視窗有三種方式,詳情可參考:
http://www.cnblogs.com/cnshen/p/3205405.html
http://shine-it.net/index.php?topic=2383.0
這裡注意讨論的是
raise osv.except_osv
()這種方式,效果圖如下:
OpenERP彈出視窗提示小結
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 "待批的"
效果圖如下