Search code examples
pythonodooopenerp-6

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.


Solution

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