问题
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(),
回答1:
You are setting the default value of date_action
as the value returned by fields.datetime.now()
, that is executed when odoo server is started.
You should set the default value as the call to the method:
'date_action': fields.datetime.now,
回答2:
try to use lambda
For example in Odoo 8 :
date_action = fields.Datetime(string="Date current action", default=lambda *a: datetime.now())
来源:https://stackoverflow.com/questions/39228319/openerp-odoo-fields-datetime-now-show-the-date-of-the-latest-restart