在odoo电子邮件模板中格式化日期

时间:2017-03-31 18:00:35

标签: openerp odoo-9

在odoo 9中,我需要在电子邮件模板中的%d /%m /%Y中格式化date_invoice:

Invoice date: ${object.date_invoice}

上面的代码返回2017-03-31,但它的位置错误。

我如何格式化以获得31/03/2017?

2 个答案:

答案 0 :(得分:2)

Qweb有一个<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:key name="kSorted" match="rule" use="@id" /> <xsl:variable name="locale" select="'en'" /> <xsl:template match="/root"> <xsl:apply-templates select="rule[generate-id() = generate-id(key('kSorted',@id)[1])]"> <xsl:sort select="@id" /> </xsl:apply-templates> </xsl:template> <xsl:template match="rule"> <xsl:variable name="thisID" select="@id" /> <row> <entry><xsl:value-of select="@id"/></entry> <entry><xsl:value-of select="//rule[@id = $thisID]//category[@locale=$locale]"/></entry> <entry><xsl:value-of select="//rule[@id = $thisID]//decidable[@locale=$locale]"/></entry> <entry> <p> <codeph><xsl:value-of select="checker/@id"/></codeph><xsl:text>&#160;</xsl:text> <xsl:value-of select="checker/*[@locale=$locale][1]"/> </p> </entry> </row> </xsl:template> </xsl:stylesheet> 函数,这是一个例子

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

现在我认为这个函数可能只适用于日期时间,但您可以在模型中添加一个新字段,该字段是根据您拥有的日期字段计算出来的,并将其称为一天。

您可以在format_tz()

找到一个用法

答案 1 :(得分:1)

您可以使用其他不同的方式实现。

$ {object.date_invoice and object.date_invoice.split(&#39; - &#39;)[1] +&#39; /&#39; + object.date_invoice.split(&#39; - &#39;)[2] +&#39; /&#39; + object.date_invoice.split(&#39; - &#39;)[0]或&#39;}

相关问题