From 58698c9aa4b04f80a6090bc9950e4ab68f4cd1f7 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 26 Mar 2024 17:57:43 +0530 Subject: [PATCH] refactor: barebones method to run checks (cherry picked from commit 8c8d9be8105918b86b80c0488557f94bc82ecebd) # Conflicts: # erpnext/accounts/utils.py --- erpnext/accounts/utils.py | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index a8338e26a2c..29c08538c94 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -13,11 +13,13 @@ from frappe.query_builder import AliasedQuery, Criterion, Table from frappe.query_builder.functions import Round, Sum from frappe.query_builder.utils import DocType from frappe.utils import ( + add_days, cint, create_batch, cstr, flt, formatdate, + get_datetime, get_number_format_info, getdate, now, @@ -2084,3 +2086,47 @@ def create_gain_loss_journal( journal_entry.save() journal_entry.submit() return journal_entry.name +<<<<<<< HEAD +======= + + +def get_party_types_from_account_type(account_type): + return frappe.db.get_all("Party Type", {"account_type": account_type}, pluck="name") + + +def run_ledger_health_checks(): + # run for last 1 month + period_end = getdate() + period_start = add_days(period_end, -100) + + run_date = get_datetime() + + # Debit-Credit mismatch report + voucher_wise = frappe.get_doc("Report", "Voucher-wise Balance") + + # todo: company and dates should be configurable + filters = {"company": "நுண்ணறி", "from_date": period_start, "to_date": period_end} + + res = voucher_wise.execute_script_report(filters=filters) + for x in res[1]: + doc = frappe.new_doc("Ledger Health") + doc.voucher_type = x.voucher_type + doc.voucher_no = x.voucher_no + doc.debit_credit_mismatch = True + doc.checked_on = run_date + doc.save() + + # General Ledger and Payment Ledger discrepancy + gl_pl_comparison = frappe.get_doc("Report", "General and Payment Ledger Comparison") + # todo: company and dates should be configurable + filters = {"company": "நுண்ணறி", "period_start_date": period_start, "period_end_date": period_end} + res = gl_pl_comparison.execute_script_report(filters=filters) + + for x in res[1]: + doc = frappe.new_doc("Ledger Health") + doc.voucher_type = x.voucher_type + doc.voucher_no = x.voucher_no + doc.general_and_payment_ledger_mismatch = True + doc.checked_on = run_date + doc.save() +>>>>>>> 8c8d9be810 (refactor: barebones method to run checks)