diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py index 897edd48c2..b9ba6810dc 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py @@ -303,9 +303,9 @@ def auto_reconcile_vouchers( vouchers = list( map( lambda entry: { - "payment_doctype": entry[1], - "payment_name": entry[2], - "amount": entry[4], + "payment_doctype": entry.get("doctype"), + "payment_name": entry.get("name"), + "amount": entry.get("paid_amount"), }, linked_payments, ) @@ -390,19 +390,13 @@ def subtract_allocations(gl_account, vouchers): "Look up & subtract any existing Bank Transaction allocations" copied = [] for voucher in vouchers: - rows = get_total_allocated_amount(voucher[1], voucher[2]) - amount = None - for row in rows: - if row["gl_account"] == gl_account: - amount = row["total"] - break + rows = get_total_allocated_amount(voucher.get("doctype"), voucher.get("name")) + filtered_row = list(filter(lambda row: row.get("gl_account") == gl_account, rows)) - if amount: - l = list(voucher) - l[3] -= amount - copied.append(tuple(l)) - else: - copied.append(voucher) + if amount := None if not filtered_row else filtered_row[0]["total"]: + voucher["paid_amount"] -= amount + + copied.append(voucher) return copied @@ -449,7 +443,9 @@ def check_matching( or [] ) - return sorted(matching_vouchers, key=lambda x: x[0], reverse=True) if matching_vouchers else [] + return ( + sorted(matching_vouchers, key=lambda x: x["rank"], reverse=True) if matching_vouchers else [] + ) def get_matching_vouchers_for_bank_reconciliation( @@ -489,12 +485,12 @@ def get_matching_vouchers_for_bank_reconciliation( ) vouchers = [] - for query in queries: vouchers.extend( frappe.db.sql( query, filters, + as_dict=True, ) ) diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py index 59905dad5d..0c328ff46c 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py @@ -47,7 +47,7 @@ class TestBankTransaction(FrappeTestCase): from_date=bank_transaction.date, to_date=utils.today(), ) - self.assertTrue(linked_payments[0][6] == "Conrad Electronic") + self.assertTrue(linked_payments[0]["party"] == "Conrad Electronic") # This test validates a simple reconciliation leading to the clearance of the bank transaction and the payment def test_reconcile(self): @@ -93,7 +93,7 @@ class TestBankTransaction(FrappeTestCase): from_date=bank_transaction.date, to_date=utils.today(), ) - self.assertTrue(linked_payments[0][3]) + self.assertTrue(linked_payments[0]["paid_amount"]) # Check error if already reconciled def test_already_reconciled(self): @@ -188,7 +188,7 @@ class TestBankTransaction(FrappeTestCase): repayment_entry = create_loan_and_repayment() linked_payments = get_linked_payments(bank_transaction.name, ["loan_repayment", "exact_match"]) - self.assertEqual(linked_payments[0][2], repayment_entry.name) + self.assertEqual(linked_payments[0]["name"], repayment_entry.name) @if_lending_app_installed diff --git a/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js b/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js index 52fa8ab0f3..1f47347d46 100644 --- a/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js +++ b/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js @@ -134,12 +134,12 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { format_row(row) { return [ - row[1], // Document Type - row[2], // Document Name - row[5] || row[8], // Reference Date - format_currency(row[3], row[9]), // Remaining - row[4], // Reference Number - row[6], // Party + row["doctype"], + row["name"], + row["reference_date"] || row["posting_date"], + format_currency(row["paid_amount"], row["currency"]), + row["reference_no"], + row["party"], ]; }