user3237836 user3237836 - 3 months ago 18
Python Question

OpenERP NameError: name '_date_of_q_created' is not defined

I am creating openerp module, in this I got the following error. I created a function
my python code is below.

_columns = {
'name' : fields.char(string="Question Title", size=256, required=True),
'description' : fields.text(string="Question Description", required=True),
'date_of_q_created': fields.function(_date_of_q_created, string='Maximum Allowed'),

'category_question': fields.many2one('openacademy.categ', 'Question Category',readonly="True"),
}

def _date_of_q_created(self):
#DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
#date_time_question = datetime.datetime.strptime(datetime.datetime.now(), DATETIME_FORMAT)
date_time_question="2014-02-04 5:50:50"
return date_time_question


error is:

File "/opt/openerp/my_modules/forum_nyros/course.py", line 9, in Course
'date_of_q_created': fields.function(_date_of_q_created, string='Maximum Allowed'),
NameError: name '_date_of_q_created' is not defined


how to get rid of this error?

Answer

python follows the top to bottom calling. paste your method top of _columns dictionary, Like this

def _date_of_q_created(self, cr, uid, ids, name, args, context=None):
        #DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
        #date_time_question = datetime.datetime.strptime(datetime.datetime.now(), DATETIME_FORMAT)
        date_time_question="2014-02-04 5:50:50"
        return date_time_question

_columns = {
            'name' : fields.char(string="Question Title", size=256, required=True),
              'description' : fields.text(string="Question Description", required=True),
              'date_of_q_created': fields.function(_date_of_q_created, string='Maximum Allowed'),

              'category_question': fields.many2one('openacademy.categ', 'Question Category',readonly="True"),
                 }

And you missed the parameters.

Comments