本文介绍了openerp Message_post错误..NameError:未定义全局名称"_"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有表单形式的chatter的自定义模块.

I have created a custom module with chatter in the form.

我要发布自定义消息.但我收到以下错误消息.

I want to post a custom message. but I am getting following error.

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)

推荐答案

尝试将其导入您的.py文件

try this to import in your .py file

通过openerp导入工具

from openerp.tools.translate import _

_ 用于翻译更改活动用户语言时所依据的消息.它将邮件翻译成您的 .po 文件中的格式.

_ is used for a translation the message when active user's language is changed according to. It's translate the message as in your .po file.

这篇关于openerp Message_post错误..NameError:未定义全局名称"_"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:20