-->

Formatting date in odoo email template

2019-08-01 02:02发布

问题:

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 ?

回答1:

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 ''}



回答2:

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