From 9209ec59c2216223bc1a7618bd95ec2424434849 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 21 Oct 2022 15:18:40 +0530 Subject: [PATCH] refactor: split delete gl utility function into two --- erpnext/accounts/utils.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index d7bf991688..103c154c5d 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1146,10 +1146,10 @@ def repost_gle_for_stock_vouchers( if not existing_gle or not compare_existing_and_expected_gle( existing_gle, expected_gle, precision ): - _delete_gl_entries(voucher_type, voucher_no) + _delete_accounting_ledger_entries(voucher_type, voucher_no) voucher_obj.make_gl_entries(gl_entries=expected_gle, from_repost=True) else: - _delete_gl_entries(voucher_type, voucher_no) + _delete_accounting_ledger_entries(voucher_type, voucher_no) if not frappe.flags.in_test: frappe.db.commit() @@ -1161,18 +1161,28 @@ def repost_gle_for_stock_vouchers( ) -def _delete_gl_entries(voucher_type, voucher_no): - frappe.db.sql( - """delete from `tabGL Entry` - where voucher_type=%s and voucher_no=%s""", - (voucher_type, voucher_no), - ) +def _delete_pl_entries(voucher_type, voucher_no): ple = qb.DocType("Payment Ledger Entry") qb.from_(ple).delete().where( (ple.voucher_type == voucher_type) & (ple.voucher_no == voucher_no) ).run() +def _delete_gl_entries(voucher_type, voucher_no): + gle = qb.DocType("GL Entry") + qb.from_(gle).delete().where( + (gle.voucher_type == voucher_type) & (gle.voucher_no == voucher_no) + ).run() + + +def _delete_accounting_ledger_entries(voucher_type, voucher_no): + """ + Remove entries from both General and Payment Ledger for specified Voucher + """ + _delete_gl_entries(voucher_type, voucher_no) + _delete_pl_entries(voucher_type, voucher_no) + + def sort_stock_vouchers_by_posting_date( stock_vouchers: List[Tuple[str, str]] ) -> List[Tuple[str, str]]: