2014-02-10 18 views
2

我在表单中创建了一个带有chatter的自定义模块。openerp Message_post error..NameError:没有定义全局名称'_'

我想发布自定义消息。但我得到以下错误。

File "/opt/openerp/my_modules/forum/forum.py", line 22, in function_which_post_msg 
    self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context) 
NameError: global name '_' is not defined 

我.py文件是

import datetime 
import time 
import openerp 
from openerp.osv import osv, fields 


class Course(osv.osv): 
    _name = "forum.course" 
    _inherit = ['mail.thread', 'ir.needaction_mixin'] 

    _columns = { 
       'name' : fields.char(string="Question Title", size=256, required=True), 
       'description' : fields.text(string="Question Description", required=True), 

       } 


    def function_which_post_msg(self, cr, uid, ids, context=None): 
     self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context) 

    def create(self, cr, uid, ids, context=None): 
     self.function_which_post_msg(cr, uid, ids, context=context) 

回答

3

试试这个从OpenERP的导入工具从openerp.tools.translate进口在你的.py文件

导入

_

_用于当活动用户的语言根据改变时的消息翻译。它会翻译该消息,如您的.po文件。

+0

有没有解决你的错误?使用此导入? –

+0

_错误已解决,但出现跟踪错误。 文件 “/opt/openerp/my_modules/forum_nyros/forum.py”,第24行,在function_which_post_msg self.message_post(CR,UID,IDS,身体= _( “新问题一直创建”), context = context) 文件“/opt/openerp/addons/mail/mail_thread.py”,第1023行,在message_post “无效的thread_id;应该是0,False,一个ID或带有一个ID的列表” – user2088432

+0

能否请您提出新的问题?所以不要重叠这个问题标题。并接受这个答案。谢谢 –

相关问题