How to format Qweb variables in Odoo

非 Y 不嫁゛ 提交于 2021-01-27 22:56:40

问题


I have been trying to display a calculated variable in qweb separated by comma's.

<td align="right">
                      <t t-set="total" t-value="0"/>
                          <t t-foreach="l.invoice_line_tax_id" t-as="t">
                          <t t-set="total" t-value="total + (t.amount * 
l.price_subtotal)" />
                          </t>
                          <span t-esc="'%.2f'%(l.price_subtotal + total)"/>

                </td>

-

This line displays the values with decimal points, whereas the digits before decimal is not separated by comma's.

For example, the above code would display value as 400000.00 whereas I would like it to be 4,00,000.00

Anyone with any idea on this.?


回答1:


This one may help you:

You need to calculate total in *.py side. by creating function field like this.

total = fields.Float('Total', compute='_cal_total') 

@api.one
def _cal_total(self):
     self.total = t.amount * l.price_subtotal

and show in *.xml field like this.

<field name="total" widget='monetary'
options="{'currency_field': 'currency_id'}" />



回答2:


Try below code,

<span><t t-esc="'{0:,.2f}'.format(inv_value)"/></span>

Hope it will help you.



来源:https://stackoverflow.com/questions/45560789/how-to-format-qweb-variables-in-odoo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!