Reputation: 81
I'm learning to customize again Odoo 9 system. Due to some characteristics of my own business I have to change some points in the account invoice template. I have created a new monetary filed with name total_residual and its value is computed by the function show bellow:
@api.multi
def _compute_all_residual(self):
for invoice in self:
invs = self.search([('state', '=', 'open'), ('partner_id', '=', invoice.partner_id.id)])
out_invoice = 0
in_invoice = 0
out_refund = 0
in_refund = 0
for inv in invs:
if inv.type == 'out_invoice':
out_invoice += inv.residual
if inv.type == 'in_invoice':
in_invoice += inv.residual
if inv.type == 'out_refund':
out_refund += inv.residual
if inv.type == 'in_refund':
in_refund += inv.residual
invoice.total_residual = out_invoice + in_refund - in_invoice - out_refund
now I would like to add a new field monetary field (old_residual) with value is total residual exclude the amount of current invoice. what is the right function to add on the module? and how come I show the value of old_residual to qweb report? thank for your time
Upvotes: 0
Views: 2038
Reputation: 136
Simply create New Monetary field and Re-write above method:
@api.multi
def _compute_all_residual(self):
for invoice in self:
invs = self.search([('state', '=', 'open'), ('partner_id', '=', invoice.partner_id.id)])
out_invoice = 0
in_invoice = 0
out_refund = 0
in_refund = 0
for inv in invs:
if inv.type == 'out_invoice':
out_invoice += inv.residual
if inv.type == 'in_invoice':
in_invoice += inv.residual
if inv.type == 'out_refund':
out_refund += inv.residual
if inv.type == 'in_refund':
in_refund += inv.residual
invoice.total_residual = out_invoice + in_refund - in_invoice - out_refund
invoice.old_residual = out_invoice + in_refund - in_invoice - out_refund - invoice.amount_total
# Define new field
old_residual = fields.Monetary(string='Amount Due', compute='_compute_all_residual', store=True)
To add above field in qweb report you need to inherit qweb template and add this field in it.
Try it with the following code in your "views/report_invoice.xml".
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_invoice_document_custom" inherit_id="account.report_invoice_document">
<xpath expr="//tr[@class='border-black']" position="after">
<!-- Your Code --->
<tr class="border-black">
<td><strong>Old Residual</strong></td>
<td class="text-right">
<span t-field="o.old_residual" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
</td>
</tr>
</xpath>
</template>
</data>
</openerp>
Add the report in youre "openerp.py" file in the data.
'data': ['views/report_invoice.xml',],
Upvotes: 1