diff --git a/account_tax_balance/__manifest__.py b/account_tax_balance/__manifest__.py index 7ea37bbe..214f2620 100644 --- a/account_tax_balance/__manifest__.py +++ b/account_tax_balance/__manifest__.py @@ -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", diff --git a/account_tax_balance/models/account_tax.py b/account_tax_balance/models/account_tax.py index 7fc2fd22..6eadace4 100644 --- a/account_tax_balance/models/account_tax.py +++ b/account_tax_balance/models/account_tax.py @@ -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( diff --git a/account_tax_balance/tests/test_account_tax_balance.py b/account_tax_balance/tests/test_account_tax_balance.py index d12a4fa9..4d4c8bfc 100644 --- a/account_tax_balance/tests/test_account_tax_balance.py +++ b/account_tax_balance/tests/test_account_tax_balance.py @@ -3,14 +3,17 @@ # Copyright 2019 Andrea Stirpe # 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)