问题
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