From 11cf694d9a1833758788d87baf70db35a87c2f08 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 14 Jan 2023 12:22:22 +0530 Subject: [PATCH 1/2] perf: improve reconciliation speed on JE's with 1000's of rows 1. No need to keep old PLE's on reconciliation. 2. Added Validation to catch debit-credit mismatch on JE's 3. Only update outstanding amount for newly reconciled invoices --- erpnext/accounts/utils.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 445dcc53c6..a03de9e194 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -439,8 +439,7 @@ def reconcile_against_document(args): # nosemgrep # cancel advance entry doc = frappe.get_doc(voucher_type, voucher_no) frappe.flags.ignore_party_validation = True - gl_map = doc.build_gl_map() - create_payment_ledger_entry(gl_map, cancel=1, adv_adj=1) + _delete_pl_entries(voucher_type, voucher_no) for entry in entries: check_if_advance_entry_modified(entry) @@ -452,11 +451,23 @@ def reconcile_against_document(args): # nosemgrep else: update_reference_in_payment_entry(entry, doc, do_not_save=True) + if doc.doctype == "Journal Entry": + try: + doc.validate_total_debit_and_credit() + except Exception as validation_exception: + raise frappe.ValidationError(_(f"Validation Error for {doc.name}")) from validation_exception + doc.save(ignore_permissions=True) # re-submit advance entry doc = frappe.get_doc(entry.voucher_type, entry.voucher_no) gl_map = doc.build_gl_map() - create_payment_ledger_entry(gl_map, cancel=0, adv_adj=1) + create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1) + + # Only update outstanding for newly linked vouchers + for entry in entries: + update_voucher_outstanding( + entry.against_voucher_type, entry.against_voucher, entry.account, entry.party_type, entry.party + ) frappe.flags.ignore_party_validation = False From 828eaf09301d84ebf78afb69e620c8d38a51e036 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sun, 15 Jan 2023 18:09:51 +0530 Subject: [PATCH 2/2] fix: minor filter issue while reconciliation tool from bench console --- .../doctype/payment_reconciliation/payment_reconciliation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index ac033f7db6..13712cee01 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -471,6 +471,7 @@ class PaymentReconciliation(Document): def build_qb_filter_conditions(self, get_invoices=False, get_return_invoices=False): self.common_filter_conditions.clear() + self.accounting_dimension_filter_conditions.clear() self.ple_posting_date_filter.clear() ple = qb.DocType("Payment Ledger Entry")