格式化相关的日期时间字段
Formatting related datetime field
我有一个相关的日期时间字段
'expected_date' : fields.related('picking_id','date',type='datetime', relation='stock.picking', store=True, string="Date"),
然后我想在某些报告中显示该字段,但我想使用此代码更改字段的格式
'picking_date' : datetime.strftime(datetime.strptime(str(expected_date), '%Y-%m-%d %H:%M:%S'),'%d-%m-%Y'),
然后我得到这个错误
time data 'None' does not match format '%Y-%m-%d %H:%M:%S'
我哪里错了?我正在使用 openerp6.
expected_date
可能是 None
所以 str(expected_date)
returns 字符串值 "None"
,因此不匹配错误。
你可能想要
'picking_date' : (expected_date is not None
and datetime.strftime(datetime.strptime(str(expected_date), '%Y-s%m-%d %H:%M:%S'),'%d-%m-%Y')
or 'None'),
我有一个相关的日期时间字段
'expected_date' : fields.related('picking_id','date',type='datetime', relation='stock.picking', store=True, string="Date"),
然后我想在某些报告中显示该字段,但我想使用此代码更改字段的格式
'picking_date' : datetime.strftime(datetime.strptime(str(expected_date), '%Y-%m-%d %H:%M:%S'),'%d-%m-%Y'),
然后我得到这个错误
time data 'None' does not match format '%Y-%m-%d %H:%M:%S'
我哪里错了?我正在使用 openerp6.
expected_date
可能是 None
所以 str(expected_date)
returns 字符串值 "None"
,因此不匹配错误。
你可能想要
'picking_date' : (expected_date is not None
and datetime.strftime(datetime.strptime(str(expected_date), '%Y-s%m-%d %H:%M:%S'),'%d-%m-%Y')
or 'None'),