From 839e42d19351baba24018298cf1e00108d32935a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 10 Dec 2024 16:33:39 +0100 Subject: [PATCH] [IMP] account_reconcile_oca: Add auto-reconcile compatibility (Example: Rule to match invoices/bills) TT52146 --- .../models/account_bank_statement_line.py | 12 +++++++++++- .../tests/test_bank_account_reconcile.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/account_reconcile_oca/models/account_bank_statement_line.py b/account_reconcile_oca/models/account_bank_statement_line.py index 439567e66f..5a78459712 100644 --- a/account_reconcile_oca/models/account_bank_statement_line.py +++ b/account_reconcile_oca/models/account_bank_statement_line.py @@ -532,7 +532,14 @@ def _default_reconcile_data(self, from_unreconcile=False): res = ( self.env["account.reconcile.model"] .search( - [("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])] + [ + ( + "rule_type", + "in", + ["invoice_matching", "writeoff_suggestion"], + ), + ("company_id", "=", self.company_id.id), + ] ) ._apply_rules(self, self._retrieve_partner()) ) @@ -555,6 +562,8 @@ def _default_reconcile_data(self, from_unreconcile=False): ) amount -= sum(line.get("amount") for line in line_data) data += line_data + if res.get("auto_reconcile"): + self.reconcile_bank_line() return self._recompute_suspense_line( data, reconcile_auxiliary_id, @@ -745,6 +754,7 @@ def create(self, mvals): models = self.env["account.reconcile.model"].search( [ ("rule_type", "in", ["invoice_matching", "writeoff_suggestion"]), + ("company_id", "in", result.mapped("company_id").ids), ("auto_reconcile", "=", True), ] ) diff --git a/account_reconcile_oca/tests/test_bank_account_reconcile.py b/account_reconcile_oca/tests/test_bank_account_reconcile.py index d2b3290ce7..287bc76f7b 100644 --- a/account_reconcile_oca/tests/test_bank_account_reconcile.py +++ b/account_reconcile_oca/tests/test_bank_account_reconcile.py @@ -10,6 +10,16 @@ class TestReconciliationWidget(TestAccountReconciliationCommon): @classmethod def setUpClass(cls, chart_template_ref=None): super().setUpClass(chart_template_ref=chart_template_ref) + # Auto-disable reconciliation model created automatically with + # generate_account_reconcile_model() to avoid side effects in tests + cls.invoice_matching_model = cls.env["account.reconcile.model"].search( + [ + ("rule_type", "=", "invoice_matching"), + ("auto_reconcile", "=", True), + ("company_id", "=", cls.company.id), + ] + ) + cls.invoice_matching_model.active = False cls.acc_bank_stmt_model = cls.env["account.bank.statement"] cls.acc_bank_stmt_line_model = cls.env["account.bank.statement.line"] @@ -988,6 +998,7 @@ def test_partner_name_with_parent(self): } ) + self.invoice_matching_model.active = True bank_stmt_line = self.acc_bank_stmt_line_model.create( { "name": "testLine",