refactor: verbosity in get_linked_payments result

- Easier to read field names like x["rank"] than x[0]
- It's hard to keep up with what the indices mean, thus reducing readability
This commit is contained in:
marination 2023-08-31 21:05:40 +05:30
parent a1ae4262c3
commit 480903e3f4
3 changed files with 22 additions and 26 deletions

View File

@ -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,
)
)

View File

@ -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

View File

@ -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"],
];
}