[FIX] account_tax_balance: Recompute balance for different dates

This commit is contained in:
SimoRubi
2021-12-09 16:08:57 +01:00
committed by Borruso
parent d4ddec2d4d
commit b446a9ebc9
3 changed files with 50 additions and 2 deletions

View File

@@ -6,7 +6,7 @@
{
"name": "Tax Balance",
"summary": "Compute tax balances based on date range",
"version": "15.0.1.0.0",
"version": "15.0.1.0.1",
"development_status": "Mature",
"category": "Invoices & Payments",
"website": "https://github.com/OCA/account-financial-reporting",

View File

@@ -81,6 +81,12 @@ class AccountTax(models.Model):
ids_with_moves = self._account_tax_ids_with_moves()
return [("id", "in", ids_with_moves)]
@api.depends_context(
"from_date",
"to_date",
"company_ids",
"target_move",
)
def _compute_balance(self):
for tax in self:
tax.balance_regular = tax.compute_balance(

View File

@@ -3,14 +3,17 @@
# Copyright 2019 Andrea Stirpe <a.stirpe@onestein.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import datetime
from datetime import datetime, timedelta
from dateutil.rrule import MONTHLY
import odoo
from odoo import fields
from odoo.fields import Date
from odoo.tests.common import HttpCase
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@odoo.tests.tagged("post_install", "-at_install")
class TestAccountTaxBalance(HttpCase):
@@ -260,3 +263,42 @@ class TestAccountTaxBalance(HttpCase):
tax.refresh()
self.assertEqual(tax.base_balance, 175.0)
self.assertEqual(tax.balance, 17.5)
class TestInvoicingBalance(AccountTestInvoicingCommon):
def test_balance_recomputation(self):
"""Check that balances are computed correctly for different dates."""
partner = self.partner_a
tax = self.tax_sale_a
today = fields.Date.today()
self.init_invoice(
"in_invoice",
partner=partner,
invoice_date=today,
post=True,
amounts=[100],
taxes=tax,
)
tomorrow = today + timedelta(days=1)
self.init_invoice(
"in_invoice",
partner=partner,
invoice_date=tomorrow,
post=True,
amounts=[200],
taxes=tax,
)
# Check today's balance
self.check_date_balance(tax, today, -15)
# Check tomorrow's balance
self.check_date_balance(tax, tomorrow, -30)
def check_date_balance(self, tax, date, balance):
"""Compare expected balance with tax's balance in specified date."""
tax = tax.with_context(
from_date=date,
to_date=date,
)
self.assertEqual(tax.balance, balance)