Odoo Help


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.


How to solve: AttributeError 'datetime.datetime' object has no attribute 'get'

on 2/9/13, 3:03 PM 5,667 views


I am new to OpenERP development and I am trying to learn how to assign functions to fields so I can retrieve values based on my needs, but after following the manual or taking a look at the code from another modules I can't seem to get it right.

I tried a really simple function to retrieve the current time into a field. Here is the code to my function

def get_text(self, cr, uid, ids, fields, arg, context):
    #records = self.browse(cr, uid, ids)
    #sale = 'Some Text'
    dd = datetime.now()
    return dd

And this is how I call the get_text function

'varText': fields.function(get_text, obj='sim.student', method=True, store=False, type='string', string='Text')

Whatever I try in my get_text function I always get an error like the following:

AttributeError: 'datetime.datetime' object has no attribute 'get'

If I comment the line starting with dd and uncomment the line starting with sale the error would be

AttributeError: 'str' object has no attribute 'get'

If anyone can give me a tip on what I am doing wrong I will really appreciate it!



Nicolas Bessi

--Nicolas Bessi--
| 5 7 8
Lausanne, Switzerland
--Nicolas Bessi--
Nicolas Bessi
On 2/9/13, 3:45 PM


  • In you field singature the obj is not requied as it is not a relation type field.
  • type='string' will not work. You should use type='char'
  • but as you try to get a datetime fields the correct type should be datetime.
  • The return of get_textshould be a dict with keys the ids of the record and values the related values

You should have a look at the hr_attendance/hr_attendance.py of addons file

'last_sign': fields.function(_last_sign, type='datetime', string='Last Sign') is a simple sample

Thanks so much, after hours of tests your help solve my problem. I always have to return an array of ids for functions being called by fields? Thanks again! =)

on 2/9/13, 5:14 PM

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)


Asked: 2/9/13, 3:03 PM
Seen: 5667 times
Last updated: 3/16/15, 8:10 AM