From a0fa785eb5f58e0f4d85c7bb56c2caf6736593e7 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 5 Jul 2019 15:10:26 +0000 Subject: [PATCH] [FIX] account: auto reconcile model with tax Set an automatic reconciliation model with a tax Create a bank statement on which one line will be caught by that model Click on reconcile to get to the reconciliation widget Observe the account move lines creates Before this commit, the move line representing the tax amount (and in the account for taxes) did not have a tax_line_id, which is a reference to the tax that made the line exist This messed up tax reports After this commit, the move line of the tax has a reference to the tax it originated from The tax reports are correct OPW 2006826 closes odoo/odoo#34627 Signed-off-by: Lucas Perais (lpe) --- .../account/models/account_reconcile_model.py | 1 + .../test_reconciliation_matching_rules.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index deff0119087..b04b2d5f303 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -154,6 +154,7 @@ class AccountReconcileModel(models.Model): 'analytic_account_id': tax.analytic and base_line_dict['analytic_account_id'], 'analytic_tag_ids': tax.analytic and base_line_dict['analytic_tag_ids'], 'tax_exigible': tax.tax_exigibility == 'on_payment', + 'tax_line_id': tax.id, }) # Handle price included taxes. diff --git a/addons/account/tests/test_reconciliation_matching_rules.py b/addons/account/tests/test_reconciliation_matching_rules.py index cb10bee162e..152de2c6478 100644 --- a/addons/account/tests/test_reconciliation_matching_rules.py +++ b/addons/account/tests/test_reconciliation_matching_rules.py @@ -98,6 +98,12 @@ class TestReconciliationMatchingRules(AccountingTestCase): 'sequence': 1, }) + self.tax21 = self.env['account.tax'].create({ + 'name': '21%', + 'type_tax_use': 'purchase', + 'amount': 21, + }) + def test_matching_fields(self): ''' Test all fields used to restrict the rules's applicability.''' @@ -304,6 +310,34 @@ class TestReconciliationMatchingRules(AccountingTestCase): {'partner_id': self.partner_2.id, 'debit': 1000.0, 'credit': 0.0}, ]) + def test_auto_reconcile_with_tax(self): + ''' Test auto reconciliation with a tax amount included in the bank statement line''' + + self.rule_1.write({ + 'auto_reconcile': True, + 'force_tax_included': True, + 'tax_id': self.tax21.id, + 'rule_type': 'writeoff_suggestion', + }) + + self.bank_line_2.unlink() + self.bank_line_1.amount = -121 + + self._check_statement_matching( + self.rule_1, + { + self.bank_line_1.id: {'aml_ids': [], 'model': self.rule_1, 'status': 'reconciled'}, + }, + self.bank_st + ) + + # Check first line has been well reconciled. + self.assertRecordValues(self.bank_line_1.journal_entry_ids, [ + {'partner_id': self.partner_1.id, 'debit': 0.0, 'credit': 121.0}, + {'partner_id': self.partner_1.id, 'debit': 21.0, 'credit': 0.0, 'tax_line_id': self.tax21.id}, + {'partner_id': self.partner_1.id, 'debit': 100.0, 'credit': 0.0, 'tax_ids': [self.tax21.id]} + ]) + def test_reverted_move_matching(self): AccountMove = self.env['account.move'] move = AccountMove.create({