Formatting date in odoo email template

2019-08-01 02:10发布

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 ?

2条回答
祖国的老花朵
2楼-- · 2019-08-01 02:21

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

查看更多
闹够了就滚
3楼-- · 2019-08-01 02:28

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

查看更多
登录 后发表回答