简体   繁体   中英

Formatting related datetime field

I have a related datetime field

'expected_date'     : fields.related('picking_id','date',type='datetime', relation='stock.picking', store=True, string="Date"),

Then I want to show that field in some report, but I want to change the format of the field using this code

'picking_date' : datetime.strftime(datetime.strptime(str(expected_date), '%Y-%m-%d %H:%M:%S'),'%d-%m-%Y'),

Then I got this error

time data 'None' does not match format '%Y-%m-%d %H:%M:%S'

Where did I go wrong? I'm using openerp6.

expected_date is probably None so str(expected_date) returns the string value "None" , hence the does not match error.

You probably want

'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'),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM