Odoo Help


fields.datetime.now() show the time of the latest restart - not the current time

on 8/30/16, 9:30 AM 3,153 views

Hi everyone,

I have a field datetime. This field should have by default the datetime of "now", the current time.

However, the default date is the time of the lastest restart.

Please find below my code:

'date_action': fields.datetime('Date current action', required=False, readonly=False, select=True),

_defaults = {
    'date_action': fields.datetime.now(),

Someones has an idea why? And how to solve it?

Many thanks,


On 9/24/17, 6:35 AM

You have to use lambda function to get the current time. Otherwise it will take the latest server restart time.

_defaults = {
'date_action': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
Ray Carnes
On 8/30/16, 10:24 AM

For v8/v9: You have not defined the field correctly, not using a CAPITAL for Datetime:

'date_action': fields.Datetime('Date current action', required=False, readonly=False, select=True),

For v7: You are mixing the API functions.


from openerp.osv import fields, osv
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT


Hi Ray. Thank you for your answer. I tried with Capital for Datetime but I have the error: AttributeError: 'module' object has no attribute 'Datetime'. Do I need to import a specific class? PS: I am using OpenERP 7 ( sorry to forgot to mention it)

on 8/30/16, 10:40 AM

See my updated answer for v7

Bista Solutions US, Ray Carnes
on 9/1/16, 10:35 PM
On 10/26/16, 2:05 AM

In V8 or above, if the class definition is as per latest api, i.e (models.Model)

then use the below like syntax, no need to import any date-related files.

date_action = fields.Datetime('Date current action', required=False, readonly=False, select=True
                                , default=lambda self: fields.datetime.now())

It works

on 11/18/16, 1:26 AM
Khaled Hamed
On 9/29/17, 12:54 AM


\Stack\ overflow\ link\ \,\ answer\ \#4\ solved\ the\ issue\ \\\

Just remove () from fields.Datetime.now()

to be:


Neha Patel (nat)
On 1/19/17, 5:29 AM

For finding current time use below code.

import time

local = time.asctime(time.localtime())

print "Current time is : ",local

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

1 follower(s)


Asked: 8/30/16, 9:30 AM
Seen: 3153 times
Last updated: 9/29/17, 12:54 AM