在OpenERP / Odoo中的Invoices Tree View中显示不同的税收作为列

时间:2016-09-26 09:29:32

标签: openerp openerp-7

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

num invoice |客户|基地0 |基地4 |基地10 |基地21 | iva 0 | iva 4 | iva 10 | iva 21 |总金额

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

我正在使用OpenERP 7,但我希望无论您使用什么版本,都可以帮助我。

1 个答案:

答案 0 :(得分:0)

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

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