Odoo Help

0

NameError: global name '_' is not defined

By
Praveen S
on 8/28/13, 2:01 PM 9,462 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([
                            ('new','New'),
                            ('assigned','Assigned'),
                            ('negotiation','Negotiation'),
                            ('won','Won'),
                            ('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    

mymod()
3
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
2
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.

Register

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)

Stats

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