ebelair
ebelair

Reputation: 884

Formatting date in odoo email template

In odoo 9 i need to format the date_invoice in %d/%m/%Y inside email template:

Invoice date: ${object.date_invoice}

The code above return 2017-03-31 but it is in wrong locale.

How i can format to get 31/03/2017 ?

Upvotes: 1

Views: 4492

Answers (2)

You can achieve using alternative different way.

${ object.date_invoice and object.date_invoice.split('-')[1] + '/' + object.date_invoice.split('-')[2] + '/' + object.date_invoice.split('-')[0] or ''}

Upvotes: 2

Phillip Stack
Phillip Stack

Reputation: 3378

Qweb has a format_tz() function here is an example

${format_tz(object.write_date, tz='UTC', format='%d/%m/%Y')}

Now I think this function may only work on a datetime but you could probably add a new field to the model which is calculated from the date field you have and call it a day.

You can find a usage here event/data/email_template_data.xml

Upvotes: 3

Related Questions