为日期时间字段 odoo 11 设置默认时间 [英] Set default time for datetime field odoo 11

查看:94
本文介绍了为日期时间字段 odoo 11 设置默认时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 odoo11 调查模块.

I am working on odoo11 survey module.

我正在从调查向导分配截止日期,向导仅包含日期字段作为截止日期.而在回答截止日期字段是日期时间及其显示 5:30 默认时间值.

I am assigning deadline from survey wizard and wizard contains only date field as deadline. whereas in Answers deadline field is datetime and its show 5:30 default time value.

我的要求:我想在答案中显示截止日期字段的默认时间是 23:59.

My requirement: I want to show default time for deadline field in Answers is 23:59.

尝试:

deadline = fields.Datetime('Deadline', help="Date by which the person can open the survey and submit answers",oldname="date_deadline", default=lambda *a: time.strftime('23:59:59'))

但它不起作用.

提前致谢

推荐答案

据我所知,您不能只为 Datetime 字段指定时间.您可以将默认值指定为特定日期时间或具有指定时间的当前日期.

As far as I know you cannot assign just a time to Datetime field. You can specify default value to be specific datetime or current date with specified time.

例如:

from odoo import fields

deadline = fields.Datetime('Deadline', oldname="date_deadline", default='2021-02-08 23:59:59')

from odoo import fields
from datetime import datetime

deadline = fields.Datetime('Deadline', oldname="date_deadline", default=lambda self: fields.Datetime.to_string(datetime.now().replace(hour=23, minute=59, second=59)))

这篇关于为日期时间字段 odoo 11 设置默认时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆