我正在学习再次定制Odoo 9系统。由于我自己的业务的一些特点,我必须更改帐户发票模板中的一些点。我创建了一个名为total_residual的新货币,其值由函数show bellow计算:
git bundle create /tmp/myrepo.bundle --all
现在我想添加一个新的字段货币字段(old_residual),其值为总剩余量,不包括当前发票金额。在模块上添加什么是正确的功能?为什么我要向qweb报告显示old_residual的价值?谢谢你的时间
答案 0 :(得分:1)
只需创建新货币字段并重写上述方法:
@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)
要在qweb报告中添加上述字段,您需要继承qweb模板并在其中添加此字段。
在“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>
在数据中添加“ openerp .py”文件中的报告。
'data': ['views/report_invoice.xml',],