Skip to content

Commit

Permalink
perf: improve reconciliation speed on JE's with 1000's of rows
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 11cf694)
  • Loading branch information
ruthra-kumar authored and mergify[bot] committed Jan 16, 2023
1 parent 623c35d commit 8a498ed
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 8a498ed

Please sign in to comment.