Odoo Help

Welcome!

This community 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.

0

NameError: global name '_' is not defined

By
Praveen S
on 8/28/13, 2:01 PM 7,160 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

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

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 _

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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