2Check for errors in business logic, terminate code execution, and Display error or warning information
Add the following code to the prompt in the class method:Raiseosv. effect_osv (_ ('error! '), _ ('Error Message .'))
Note: The osv. effect_osv () method requires two parameters. If you put the parameter in _ (), the parameter can be internationalized without _ () 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
Translation tips
#. module: qingjia
#: code:addons/qingjia/qingjia.py:0
#, Python-formatmsgid "Warning! "Msgstr" prompt! "
#. module: qingjia#: code:addons/qingjia/qingjia.py:0
#, python-formatmsgid "you cannot prove yourself"
Msgstr "You cannot approve your application form"
3)The prompt can contain variables and Chinese translation of the variables.
Def assistant_depmanager_proved_new (self, cr, uid, ids, context = None): res = self. browse (cr, uid, ids, context = context) result = res [0] raise osv. effect_osv (_ ('error! '), _ ('Your uid is "% s", name is "% s", the state is "% s"') % (_ (uid ), _ ('wang Xiaobo '), _ (result. state) result = self. _ assistant_depmanager_prove (cr, uid, ids, context = context) if result: self. write (cr, uid, ids, {'state': 'provided '})
Note: The Status translation here is the corresponding English status name. If you need to translate it into Chinese, you must use _()
#. module: qingjia#: code:addons/qingjia/qingjia.py:0
#, python-format
msgid "Your uid is \"%s\" ,name is \"%s\",the state is \"%s\""
Msgstr "Your User ID is '% s' and the name is' % s'. The status of the ticket is '% S '"
Translate all the States defined, and the final State will also be in Chinese.
#. module: qingjia
#: code:addons/qingjia/qingjia.py:0
#, python-format
Msgid "wait_prove" msgstr "to be approved"
As follows: