Skip to content

Commit

Permalink
[FIX] l10n_es_aeat_sii: Compute currency taxes amounts with proper date
Browse files Browse the repository at this point in the history
If there's an accounting date, taxes amounts in company currency are not properly
computed.

The method has been refactored as well for using the modern `_convert` method.
  • Loading branch information
pedrobaeza committed Aug 14, 2020
1 parent 5dfc277 commit 8199987
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion l10n_es_aeat_sii/__manifest__.py
Expand Up @@ -12,7 +12,7 @@

{
"name": "Suministro Inmediato de Información en el IVA",
"version": "12.0.1.5.0",
"version": "12.0.1.5.1",
"category": "Accounting & Finance",
"website": "https://odoospain.odoo.com",
"author": "Acysos S.L.,"
Expand Down
23 changes: 12 additions & 11 deletions l10n_es_aeat_sii/models/account_invoice_tax.py
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Comunitea - Omar Castiñeira <omar@comunitea.com>
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class AccountInvoiceTax(models.Model):

_inherit = "account.invoice.tax"

base_company = fields.Monetary(
Expand All @@ -18,18 +17,20 @@ class AccountInvoiceTax(models.Model):
compute="_compute_base_amount_company",
)

@api.multi
def _compute_base_amount_company(self):
for tax in self:
if (tax.invoice_id.currency_id !=
tax.invoice_id.company_id.currency_id):
currency = tax.invoice_id.currency_id.with_context(
date=tax.invoice_id.date_invoice,
company_id=tax.invoice_id.company_id.id)
tax.base_company = currency.compute(
tax.base, tax.invoice_id.company_id.currency_id)
tax.amount_company = currency.compute(
tax.amount, tax.invoice_id.company_id.currency_id)
rate_date = (
tax.invoice_id._get_currency_rate_date() or
fields.Date.today()
)
currency = tax.invoice_id.currency_id
company = tax.invoice_id.company_id
tax.base_company = currency._convert(
tax.base, company.currency_id, company, rate_date)
tax.amount_company = currency._convert(
tax.amount, company.currency_id, company, rate_date)
else:
tax.base_company = tax.base
tax.amount_company = tax.amount

0 comments on commit 8199987

Please sign in to comment.