Odoo Help


NameError: global name '_' is not defined

Praveen S
on 8/28/13, 2:01 PM 10,770 views

Hai i am new to openERP When i execute the mymod_assigned function i got the above error on line 27. My code is pasted below.The error is in that function on raise osv.except_osv(). Pls help me....

from openerp import pooler
from openerp.osv import fields, osv
from openerp import netsvc

class mymod(osv.Model):
    _name = 'mymod.mymod'    
    _columns = {
        'name': fields.char('Name', size = 100), 
        'dob': fields.date('Date of birth'),
        'father_name': fields.char('Father Name', size = 100),
        'state': fields.selection([
                            ('lost','Lost')], 'Stage', readonly=True),

    def mymod_new(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'new'})
         return True

    def mymod_assigned(self, cr, uid, ids,context=None):
         for o in self.browse(cr, uid, ids):
             if (o.state =='new'):
                 raise osv.except_osv(_('Error!'),_('You cannot confirm a sales order which has no line.'))
             self.write(cr, uid, ids, {'state': 'assigned'})
         return True

    def mymod_negotiation(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'negotiation'})
         return True

    def mymod_won(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'won'})
         return True

    def mymod_lost(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'lost'})
         return True    


Grover Menacho

--Grover Menacho--
WebVision Enterprise Systems
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Odoo Developer

Grover Menacho
On 8/28/13, 2:06 PM

You have to add this to the header

from tools.translate import _

Thanks Grover

Praveen S
on 8/28/13, 2:40 PM
Himanshu Bhandari
On 3/30/15, 8:31 AM

Above didn't worked for me, may be because I am using Odoo 8.

This one worked:

from openerp.tools.translate import _

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 8/28/13, 2:01 PM
Seen: 10770 times
Last updated: 3/30/15, 8:31 AM