account.invoice add custom computed & filtered field
<p>I'm sorry for my English</p>

<p>I am writing a custom Odoo module and my goal is add a custom computed field in account.invoice with the sum of every tax value stored in tax_line_ids amount field (excluding negative withholdings); this is my code:</p>

<pre><code># -*- coding: utf-8 -*-
from openerp import models, fields, api

class account_invoice(models.Model):
    _inherit = 'account.invoice'
    x_sum_stored_taxes_exclude_withholding = fields.Float('Total Taxes', compute='_compute_total_taxes', digits=(12,2), store=True)

    @api.one
    @api.depends('tax_line_ids.amount')
    def _compute_total_taxes(self):
        for record in self:
                record.x_sum_stored_taxes_exclude_withholding = sum(line.amount for line in record.x_sum_stored_taxes_exclude_withholding)
</code></pre>

<p>But the result in the new field "x_sum_stored_taxes_exclude_withholding" is filled only with zero's. I really tried many ways and I can not find the right one!</p>

<p>Help!!
:'(</p>

<pre class="lang-py prettyprint-override"><code>record.x_sum_stored_taxes_exclude_withholding =\
     sum(line.amount for line in record.x_sum_stored_taxes_exclude_withholding)
</code></pre>

<p>You should use `tax_line_ids ?</p>

<pre class="lang-py prettyprint-override"><code>record.x_sum_stored_taxes_exclude_withholding =\
     sum([line.amount for line in record.tax_line_ids])
</code></pre>

<p>And ofcourse you need only positive values:</p>

<pre class="lang-py prettyprint-override"><code>record.x_sum_stored_taxes_exclude_withholding =\
     sum([line.amount for line in record.tax_line_ids if line.amount &gt;= 0.0])
</code></pre>

python openerp odoo-8 odoo-9