From 900cc15ae9f5bca27b296a6111e24288d50340b1 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Wed, 31 Jul 2024 16:46:08 +0200 Subject: [PATCH] [IMP] account_reconcile_oca: Use receivable/payable account on statements with partner as suspense account --- .../models/account_bank_statement_line.py | 12 +++-- .../tests/test_bank_account_reconcile.py | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/account_reconcile_oca/models/account_bank_statement_line.py b/account_reconcile_oca/models/account_bank_statement_line.py index ddf8a8dcaf..4e46c7052c 100644 --- a/account_reconcile_oca/models/account_bank_statement_line.py +++ b/account_reconcile_oca/models/account_bank_statement_line.py @@ -227,13 +227,17 @@ def _recompute_suspense_line( } ) else: + account = self.journal_id.suspense_account_id + if self.partner_id and total_amount > 0: + can_reconcile = True + account = self.partner_id.property_account_receivable_id + elif self.partner_id and total_amount < 0: + can_reconcile = True + account = self.partner_id.property_account_payable_id suspense_line = { "reference": "reconcile_auxiliary;%s" % reconcile_auxiliary_id, "id": False, - "account_id": [ - self.journal_id.suspense_account_id.id, - self.journal_id.suspense_account_id.display_name, - ], + "account_id": [account.id, account.display_name], "partner_id": self.partner_id and [self.partner_id.id, self.partner_id.display_name] or (self.partner_name and (False, self.partner_name)) diff --git a/account_reconcile_oca/tests/test_bank_account_reconcile.py b/account_reconcile_oca/tests/test_bank_account_reconcile.py index ff1fdfa933..14762e2f9b 100644 --- a/account_reconcile_oca/tests/test_bank_account_reconcile.py +++ b/account_reconcile_oca/tests/test_bank_account_reconcile.py @@ -1020,3 +1020,51 @@ def test_journal_foreign_currency(self): self.assertTrue(bank_stmt_line.can_reconcile) bank_stmt_line.reconcile_bank_line() self.assertEqual(0, inv1.amount_residual) + + def test_receivable_line(self): + bank_stmt_line = self.acc_bank_stmt_line_model.create( + { + "name": "testLine", + "journal_id": self.bank_journal_euro.id, + "partner_id": self.partner_agrolait_id, + "amount": 100, + "date": time.strftime("%Y-07-15"), + } + ) + self.assertTrue(bank_stmt_line.can_reconcile) + suspense_line = False + for line in bank_stmt_line.reconcile_data_info["data"]: + if line["kind"] == "suspense": + suspense_line = line + break + self.assertTrue(suspense_line) + self.assertEqual( + self.env["account.account"] + .browse(suspense_line["account_id"][0]) + .account_type, + "asset_receivable", + ) + + def test_payable_line(self): + bank_stmt_line = self.acc_bank_stmt_line_model.create( + { + "name": "testLine", + "journal_id": self.bank_journal_euro.id, + "partner_id": self.partner_agrolait_id, + "amount": -100, + "date": time.strftime("%Y-07-15"), + } + ) + self.assertTrue(bank_stmt_line.can_reconcile) + suspense_line = False + for line in bank_stmt_line.reconcile_data_info["data"]: + if line["kind"] == "suspense": + suspense_line = line + break + self.assertTrue(suspense_line) + self.assertEqual( + self.env["account.account"] + .browse(suspense_line["account_id"][0]) + .account_type, + "liability_payable", + )