在 OpenERP/Odoo 的发票树视图中将不同的税显示为列

Show different taxes as columns in Invoices Tree View in OpenERP/Odoo

西班牙一张发票可能有不同的税费:IVA 0%、IVA 4%、IVA 10%、IVA 21%。我需要在树视图中将所有这些税显示为列,无论它们是否都出现在同一张发票中。例如:

发票数量 |客户 |基地 0 |基地 4 |基数 10 |基数 21 |伊娃 0 |伊娃 4 |伊娃 10 |伊娃 21 |总金额

我应该怎么做才能获得可用税收和税基的列表并将它们作为列放在树视图中并在每行中显示相应的金额 (如果征税)?

我用的是OpenERP 7,不管你用的是什么版本,希望你能帮帮我。

以下代码是我的解决方案:

# -*- coding: utf-8 -*-
from openerp import models, fields, api, _

# mapping payment method with its human descriptions
PAYMENT_METHODS = [
    ('bank_transfer', 'Bank transfer'),
    ('commerce_cod', 'Bank debit'),
    ('commerce_sermepa', 'Credit card (POS)'),
    ('commerce_stripe', 'Credit card'),
    ('pagamastarde', 'Funded payment'),
    ('paypal_wps', 'PayPal'),
]

class account_invoice_resume(models.Model):
    _name = 'account.invoice.resume'
    _inherit = 'account.invoice'
    _order = 'date_invoice asc, id asc'
    _table = 'account_invoice'

    @api.depends('partner_id','partner_id.parent_id')
    def _get_partner_parent_name(self):
        for invoice in self:
            if invoice.partner_id.parent_id:
                name = invoice.partner_id.parent_id.name
            else:
                name = invoice.partner_id.name

            invoice.display_name = name

    # Sum products amount for each type of tax and base
    @api.depends('tax_line.name','tax_line.amount','tax_line.base')
    def _specific_tax_amount(self):

        for invoice in self:
            invoice.tax_base_0 = invoice.tax_base_4 = invoice.tax_base_10 = invoice.tax_base_21 = invoice.tax_iva_4 = invoice.tax_iva_10 = invoice.tax_iva_21 = 0.0
            amount_without_taxes = invoice.amount_total # Final total of products without taxes or with tax 0%
            if len(invoice.tax_line) > 0:
                for line in invoice.tax_line:
                    _tax = line.name.strip()
                    amount = line.amount
                    base = line.base

                    if _tax in ['21% IVA soportado (bienes corrientes)','IVA 21% (Bienes)','IVA 21% (Servicios)']: # If tax is IVA 21%
                        invoice.tax_iva_21 += amount
                        invoice.tax_base_21 += base
                        amount_without_taxes -= amount + base
                    elif _tax in ['10% IVA soportado (bienes corrientes)','IVA 10% (Bienes)','IVA 10% (Servicios)']: # If tax is IVA 10%
                        invoice.tax_iva_10 += amount
                        invoice.tax_base_10 += base
                        amount_without_taxes -= amount + base
                    elif _tax in ['4% IVA soportado (bienes corrientes)','IVA 4% (Bienes)']: # If tax is IVA 4%
                        invoice.tax_iva_4 += amount
                        invoice.tax_base_4 += base
                        amount_without_taxes -= amount + base
                    elif _tax is None or _tax in ['','IVA 0% Entregas Intracomunitarias exentas','IVA 0% Exportaciones','IVA Soportado exento (operaciones corrientes)']: # If tax is IVA 0%
                        invoice.tax_base_0 += base
                        amount_without_taxes -= base

                # Sum residual amount of prices without 4%, 10% o r21% taxes to base 0
                invoice.tax_base_0 += amount_without_taxes
            else:
                invoice.tax_base_0 = invoice.amount_total

account_invoices_resume()