user6009583
user6009583

Reputation:

account.invoice add custom computed & filtered field

I'm sorry for my English

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:

# -*- 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)

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!

Help!! :'(

Upvotes: 1

Views: 194

Answers (1)

CZoellner
CZoellner

Reputation: 14768

record.x_sum_stored_taxes_exclude_withholding =\
     sum(line.amount for line in record.x_sum_stored_taxes_exclude_withholding)

You should use `tax_line_ids ?

record.x_sum_stored_taxes_exclude_withholding =\
     sum([line.amount for line in record.tax_line_ids])

And ofcourse you need only positive values:

record.x_sum_stored_taxes_exclude_withholding =\
     sum([line.amount for line in record.tax_line_ids if line.amount >= 0.0])

Upvotes: 1

Related Questions