I'm trying to display tax percentage instead of their name in accounting > customer invoices
I want to have the percentage from accounting > configuration > taxes > taxes
I don't know how to achieve this
The name_get returns a textual representation for the records in self
.
By default, this is the value of the display_name
field.
The method was redefined in account.tax to use the description (Code) field or the name field. In the following example, we will override the same method to show the tax amount percentage.
class AccountTax(models.Model):
_inherit = 'account.tax'
@api.multi
def name_get(self):
res = []
for record in self:
percentage = int(record.amount * 100)
name = str(percentage) + "%"
res.append((record.id, name))
return res
Edit:
To use the same representation in invoice report (which uses the name field for tax name), just call the name_get
function to get the display name.
Example: Inherit invoice report to use the display name instead of tax name
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//tbody[hasclass('invoice_tbody')]/tr/td[5]/span" position="attributes">
<attribute name="t-esc">', '.join(map(lambda x: x.name_get()[0][1], l.invoice_line_tax_id))</attribute>
</xpath>
</template>