Question

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

my .py file is

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)
Was it helpful?

Solution

try this to import in your .py file

from openerp import tools

from openerp.tools.translate import _

_ 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top