This question has been flagged
4 Replies
29166 Views

Hi. I create a field date in my module class file, and I want to put automatically the day of today (for example) as default date. Help me please. thx

Avatar
Discard

from_date = fields.Date(string="From Date" ,default=datetime.now())

Author Best Answer

ok thx, it works, I do this :

_defaults= {
    'record_date': fields.date.context_today,
}
Avatar
Discard
Best Answer

import time

admission_date = fields.Date('Admission Date', default=date.today())


In this code is used to generate default current date

Avatar
Discard
Best Answer

You have to add this:

import time

and you can add this to _defaults

    _defaults= {
    'date_field': lambda *a: time.strftime('%Y-%m-%d'),
}
Avatar
Discard