From 67c906f4d2ce5f150b77fe0f353e6688696318b0 Mon Sep 17 00:00:00 2001 From: "Hbto [ Vauxoo ]" Date: Fri, 24 Jun 2022 19:52:08 +0000 Subject: [PATCH] [FIX] account: Do not create cash basis entries on non-cash-basis Company Chances are that Journal Entries are coming from previous migration and they could trigger the creation of CABA Journal Entries even when the company at stake is a non Cash Basis Company. closes odoo/odoo#98954 X-original-commit: fcad4dbdbd65775b75aa94049da06bd0b07295d8 Related: odoo/enterprise#30763 Signed-off-by: Laurent Smet --- addons/account/models/account_move_line.py | 2 +- .../tests/test_account_move_date_algorithm.py | 2 ++ addons/account/tests/test_account_move_entry.py | 1 + .../tests/test_account_move_in_invoice.py | 1 + .../tests/test_account_move_in_refund.py | 1 + .../tests/test_account_move_out_invoice.py | 1 + .../tests/test_account_move_out_refund.py | 1 + .../tests/test_account_move_reconcile.py | 17 +++++++++++++++++ ...test_anglo_saxon_valuation_reconciliation.py | 1 + 9 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 30c0712f071..b3d0c577626 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -2226,7 +2226,7 @@ class AccountMoveLine(models.Model): # ==== Create entries for cash basis taxes ==== - is_cash_basis_needed = account.account_type in ('asset_receivable', 'liability_payable') + is_cash_basis_needed = account.company_id.tax_exigibility and account.account_type in ('asset_receivable', 'liability_payable') if is_cash_basis_needed and not self._context.get('move_reverse_cancel'): tax_cash_basis_moves = partials._create_tax_cash_basis_moves() results['tax_cash_basis_moves'] = tax_cash_basis_moves diff --git a/addons/account/tests/test_account_move_date_algorithm.py b/addons/account/tests/test_account_move_date_algorithm.py index 7d674b7a24e..0d84634f76f 100644 --- a/addons/account/tests/test_account_move_date_algorithm.py +++ b/addons/account/tests/test_account_move_date_algorithm.py @@ -182,6 +182,8 @@ class TestAccountMoveDateAlgorithm(AccountTestInvoicingCommon): }]) def test_caba_with_lock_date(self): + self.env.company.tax_exigibility = True + tax_waiting_account = self.env['account.account'].create({ 'name': 'TAX_WAIT', 'code': 'TWAIT', diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index 95d63289656..eafc065d0ce 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -649,6 +649,7 @@ class TestAccountMove(AccountTestInvoicingCommon): 'company_id': self.company_data['company'].id, }) self.env.company.account_cash_basis_base_account_id = tax_base_amount_account + self.env.company.tax_exigibility = True tax_tags = defaultdict(dict) for line_type, repartition_type in [(l, r) for l in ('invoice', 'refund') for r in ('base', 'tax')]: tax_tags[line_type][repartition_type] = self.env['account.account.tag'].create({ diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index e0159af9f1c..4fb0765dd26 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -1853,6 +1853,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'company_id': self.company_data['company'].id, }) self.env.company.account_cash_basis_base_account_id = tax_base_amount_account + self.env.company.tax_exigibility = True tax_tags = defaultdict(dict) for line_type, repartition_type in [(l, r) for l in ('invoice', 'refund') for r in ('base', 'tax')]: tax_tags[line_type][repartition_type] = self.env['account.account.tag'].create({ diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py index 7416bf4dc89..7546a04e77c 100644 --- a/addons/account/tests/test_account_move_in_refund.py +++ b/addons/account/tests/test_account_move_in_refund.py @@ -1026,6 +1026,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'company_id': self.company_data['company'].id, }) self.env.company.account_cash_basis_base_account_id = tax_base_amount_account + self.env.company.tax_exigibility = True tax_tags = defaultdict(dict) for line_type, repartition_type in [(l, r) for l in ('invoice', 'refund') for r in ('base', 'tax')]: tax_tags[line_type][repartition_type] = self.env['account.account.tag'].create({ diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index f4fd3df5d8d..f6f0e12823b 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3149,6 +3149,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'company_id': self.company_data['company'].id, }) self.env.company.account_cash_basis_base_account_id = tax_base_amount_account + self.env.company.tax_exigibility = True tax_tags = defaultdict(dict) for line_type, repartition_type in [(l, r) for l in ('invoice', 'refund') for r in ('base', 'tax')]: tax_tags[line_type][repartition_type] = self.env['account.account.tag'].create({ diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py index 47f6b713bae..df6fc0f65af 100644 --- a/addons/account/tests/test_account_move_out_refund.py +++ b/addons/account/tests/test_account_move_out_refund.py @@ -982,6 +982,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'company_id': self.company_data['company'].id, }) self.env.company.account_cash_basis_base_account_id = tax_base_amount_account + self.env.company.tax_exigibility = True tax_tags = defaultdict(dict) for line_type, repartition_type in [(l, r) for l in ('invoice', 'refund') for r in ('base', 'tax')]: tax_tags[line_type][repartition_type] = self.env['account.account.tag'].create({ diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index e121943c10f..6037f4513a5 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -2353,6 +2353,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): - Check there is no rounding issue when making the percentage. - Check there is no lost cents when the journal entry is fully reconciled. ''' + self.env.company.tax_exigibility = True self.cash_basis_tax_tiny_amount.amount = 0.01 cash_basis_move = self.env['account.move'].with_context(skip_invoice_sync=True).create({ 'move_type': 'entry', @@ -2559,6 +2560,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): def test_reconcile_cash_basis_workflow_multi_currency(self): ''' Same as before with a foreign currency. ''' + self.env.company.tax_exigibility = True currency_id = self.currency_data['currency'].id taxes = self.cash_basis_tax_a_third_amount + self.cash_basis_tax_tiny_amount @@ -2784,6 +2786,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ''' Test the generation of the exchange difference for a tax cash basis journal entry when the transfer account is not reconcilable. ''' + self.env.company.tax_exigibility = True currency_id = self.currency_data['currency'].id # Rate 1/3 in 2016. @@ -2914,6 +2917,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ''' Test the generation of the exchange difference for a tax cash basis journal entry when the transfer account is not a reconcile one. ''' + self.env.company.tax_exigibility = True currency_id = self.setup_multi_currency_data(default_values={ 'name': 'bitcoin', 'symbol': 'bc', @@ -3002,6 +3006,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ''' Test the generation of the exchange difference for a tax cash basis journal entry when the transfer account is not a reconcile one. ''' + self.env.company.tax_exigibility = True currency_id = self.setup_multi_currency_data(default_values={ 'name': 'bitcoin', 'symbol': 'bc', @@ -3091,6 +3096,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ''' Test the generation of the exchange difference for a tax cash basis journal entry when the tax account is a reconcile one. ''' + self.env.company.tax_exigibility = True currency_id = self.currency_data['currency'].id cash_basis_transition_account = self.env['account.account'].create({ 'code': '209.01.01', @@ -3204,6 +3210,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): def test_reconcile_cash_basis_revert(self): ''' Ensure the cash basis journal entry can be reverted. ''' + self.env.company.tax_exigibility = True self.cash_basis_transfer_account.reconcile = True self.cash_basis_tax_a_third_amount.cash_basis_transition_account_id = self.tax_account_1 @@ -3285,6 +3292,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.assertFullReconcile(reversed_taxes_full_reconcile, reversed_taxes_lines) def test_reconcile_cash_basis_tax_grid_refund(self): + self.env.company.tax_exigibility = True invoice_move = self.env['account.move'].create({ 'move_type': 'entry', 'date': '2016-01-01', @@ -3414,6 +3422,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): def test_reconcile_cash_basis_tax_grid_multi_taxes(self): ''' Test the tax grid when reconciling an invoice with multiple taxes/tax repartition. ''' + self.env.company.tax_exigibility = True base_taxes = self.cash_basis_tax_a_third_amount + self.cash_basis_tax_tiny_amount base_tags = self.tax_tags[0] + self.tax_tags[4] @@ -3491,6 +3500,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): # Make the tax account reconcilable self.tax_account_1.reconcile = True + self.env.company.tax_exigibility = True # Create a tax using the same accounts as the CABA one non_caba_tax = self.env['account.tax'].create({ @@ -3567,6 +3577,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.env.user.groups_id += self.env.ref('analytic.group_analytic_accounting') # Make the tax account reconcilable self.tax_account_1.reconcile = True + self.env.company.tax_exigibility = True # Create an invoice with a CABA tax using 'Include in analytic cost' move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice', account_predictive_bills_disable_prediction=True)) @@ -3615,6 +3626,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): def test_caba_double_tax_negative_line(self): """ Tests making a cash basis invoice with 2 lines using the same tax: a positive and a negative one. """ + self.env.company.tax_exigibility = True invoice = self.init_invoice('in_invoice', amounts=[300, -60], post=True, taxes=self.cash_basis_tax_a_third_amount) pmt_wizard = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=invoice.ids).create({ @@ -3647,6 +3659,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): # Make the tax account reconcilable self.tax_account_1.reconcile = True + self.env.company.tax_exigibility = True # Create an invoice with a CABA tax using the same tax account and pay half of it caba_inv = self.init_invoice('in_invoice', amounts=[900], post=True, taxes=self.cash_basis_tax_a_third_amount) @@ -3715,6 +3728,8 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): bill.button_draft() def test_caba_foreign_vat(self): + self.env.company.tax_exigibility = True + test_country = self.env['res.country'].create({ 'name': "Bretonnia", 'code': 'wh', @@ -3772,6 +3787,8 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): """ Test the CABA entries generated from an invoice with a tax group """ + self.env.company.tax_exigibility = True + # Make the tax account reconcilable self.tax_account_1.reconcile = True diff --git a/addons/purchase_stock/tests/test_anglo_saxon_valuation_reconciliation.py b/addons/purchase_stock/tests/test_anglo_saxon_valuation_reconciliation.py index e3d6873bac2..beb29be6d88 100644 --- a/addons/purchase_stock/tests/test_anglo_saxon_valuation_reconciliation.py +++ b/addons/purchase_stock/tests/test_anglo_saxon_valuation_reconciliation.py @@ -213,6 +213,7 @@ class TestValuationReconciliation(ValuationReconciliationTestCommon): def test_reconcile_cash_basis_bill(self): ''' Test the generation of the CABA move after bill payment ''' + self.env.company.tax_exigibility = True cash_basis_base_account = self.env['account.account'].create({ 'code': 'cash.basis.base.account', 'name': 'cash_basis_base_account',