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:
parent
a1ae4262c3
commit
480903e3f4
@ -303,9 +303,9 @@ def auto_reconcile_vouchers(
|
|||||||
vouchers = list(
|
vouchers = list(
|
||||||
map(
|
map(
|
||||||
lambda entry: {
|
lambda entry: {
|
||||||
"payment_doctype": entry[1],
|
"payment_doctype": entry.get("doctype"),
|
||||||
"payment_name": entry[2],
|
"payment_name": entry.get("name"),
|
||||||
"amount": entry[4],
|
"amount": entry.get("paid_amount"),
|
||||||
},
|
},
|
||||||
linked_payments,
|
linked_payments,
|
||||||
)
|
)
|
||||||
@ -390,19 +390,13 @@ def subtract_allocations(gl_account, vouchers):
|
|||||||
"Look up & subtract any existing Bank Transaction allocations"
|
"Look up & subtract any existing Bank Transaction allocations"
|
||||||
copied = []
|
copied = []
|
||||||
for voucher in vouchers:
|
for voucher in vouchers:
|
||||||
rows = get_total_allocated_amount(voucher[1], voucher[2])
|
rows = get_total_allocated_amount(voucher.get("doctype"), voucher.get("name"))
|
||||||
amount = None
|
filtered_row = list(filter(lambda row: row.get("gl_account") == gl_account, rows))
|
||||||
for row in rows:
|
|
||||||
if row["gl_account"] == gl_account:
|
|
||||||
amount = row["total"]
|
|
||||||
break
|
|
||||||
|
|
||||||
if amount:
|
if amount := None if not filtered_row else filtered_row[0]["total"]:
|
||||||
l = list(voucher)
|
voucher["paid_amount"] -= amount
|
||||||
l[3] -= amount
|
|
||||||
copied.append(tuple(l))
|
copied.append(voucher)
|
||||||
else:
|
|
||||||
copied.append(voucher)
|
|
||||||
return copied
|
return copied
|
||||||
|
|
||||||
|
|
||||||
@ -449,7 +443,9 @@ def check_matching(
|
|||||||
or []
|
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(
|
def get_matching_vouchers_for_bank_reconciliation(
|
||||||
@ -489,12 +485,12 @@ def get_matching_vouchers_for_bank_reconciliation(
|
|||||||
)
|
)
|
||||||
|
|
||||||
vouchers = []
|
vouchers = []
|
||||||
|
|
||||||
for query in queries:
|
for query in queries:
|
||||||
vouchers.extend(
|
vouchers.extend(
|
||||||
frappe.db.sql(
|
frappe.db.sql(
|
||||||
query,
|
query,
|
||||||
filters,
|
filters,
|
||||||
|
as_dict=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class TestBankTransaction(FrappeTestCase):
|
|||||||
from_date=bank_transaction.date,
|
from_date=bank_transaction.date,
|
||||||
to_date=utils.today(),
|
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
|
# This test validates a simple reconciliation leading to the clearance of the bank transaction and the payment
|
||||||
def test_reconcile(self):
|
def test_reconcile(self):
|
||||||
@ -93,7 +93,7 @@ class TestBankTransaction(FrappeTestCase):
|
|||||||
from_date=bank_transaction.date,
|
from_date=bank_transaction.date,
|
||||||
to_date=utils.today(),
|
to_date=utils.today(),
|
||||||
)
|
)
|
||||||
self.assertTrue(linked_payments[0][3])
|
self.assertTrue(linked_payments[0]["paid_amount"])
|
||||||
|
|
||||||
# Check error if already reconciled
|
# Check error if already reconciled
|
||||||
def test_already_reconciled(self):
|
def test_already_reconciled(self):
|
||||||
@ -188,7 +188,7 @@ class TestBankTransaction(FrappeTestCase):
|
|||||||
repayment_entry = create_loan_and_repayment()
|
repayment_entry = create_loan_and_repayment()
|
||||||
|
|
||||||
linked_payments = get_linked_payments(bank_transaction.name, ["loan_repayment", "exact_match"])
|
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
|
@if_lending_app_installed
|
||||||
|
@ -134,12 +134,12 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
|||||||
|
|
||||||
format_row(row) {
|
format_row(row) {
|
||||||
return [
|
return [
|
||||||
row[1], // Document Type
|
row["doctype"],
|
||||||
row[2], // Document Name
|
row["name"],
|
||||||
row[5] || row[8], // Reference Date
|
row["reference_date"] || row["posting_date"],
|
||||||
format_currency(row[3], row[9]), // Remaining
|
format_currency(row["paid_amount"], row["currency"]),
|
||||||
row[4], // Reference Number
|
row["reference_no"],
|
||||||
row[6], // Party
|
row["party"],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user