以下代码是我的解决方案:
# -*- 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()