openerp Message_post error..NameError:未定义全局名称“_”

时间:2014-02-10 07:35:36

标签: python openerp

我在表单中创建了一个带有聊天功能的自定义模块。

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

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)

1 个答案:

答案 0 :(得分:3)

尝试将其导入.py文件

来自openerp导入工具的

来自openerp.tools.translate import _

_ 用于在根据活动用户的语言更改时翻译邮件。它会将您的消息翻译为 .po 文件。