OpenERP/Odoo: fields.datetime.now() show the date of the latest restart

懵懂的女人 提交于 2021-02-08 06:52:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!