【问题标题】:Show different taxes as columns in Invoices Tree View in OpenERP/Odoo在 OpenERP/Odoo 的发票树视图中将不同的税款显示为列
【发布时间】:2016-09-26 09:29:31
【问题描述】:

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

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

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

我使用的是OpenERP 7,但无论你使用什么版本,我都希望你能帮助我。

【问题讨论】:

  • 您可以在account.invoice 上创建一些功能字段并将它们添加到树/列表视图中。那将是一个非常特殊的自定义,但它应该可以工作。
  • 是的,这就是我的解决方案。谢谢。

标签: openerp openerp-7


【解决方案1】:

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

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

【讨论】:

  • 'if line.tax_code_id.id in [71,140]:' 中的那些值是什么?
  • 他们是一些 id。但是在 Odoo 上有一种不同的方法可以做到这一点。我现在正在更新我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-09
  • 2013-08-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多