Sembarangan
Sembarangan

Reputation: 45

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.

Upvotes: 0

Views: 87

Answers (1)

Vin-G
Vin-G

Reputation: 4950

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

Upvotes: 2

Related Questions