From 10e4b9d4e8b7bcc594de32dff10effeed6b970c0 Mon Sep 17 00:00:00 2001 From: UrvashiKishnani <41088003+UrvashiKishnani@users.noreply.github.com> Date: Mon, 1 Mar 2021 12:50:07 +0400 Subject: [PATCH 1/2] fix: GL Entries for AP/AR Summary SQL query modified to fetch only those GL Entries for Accounts Payable Summary and Accounts Receivable Summary reports where the corresponding payment entry is in submitted state. --- erpnext/accounts/party.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 38b228477f7..7d53db2dc37 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -606,18 +606,20 @@ def get_partywise_advanced_payment_amount(party_type, posting_date = None, futur cond = "1=1" if posting_date: if future_payment: - cond = "posting_date <= '{0}' OR DATE(creation) <= '{0}' """.format(posting_date) + cond = "gle.posting_date <= '{0}' OR DATE(creation) <= '{0}' """.format(posting_date) else: - cond = "posting_date <= '{0}'".format(posting_date) + cond = "gle.posting_date <= '{0}'".format(posting_date) if company: - cond += "and company = {0}".format(frappe.db.escape(company)) + cond += "and gle.company = {0}".format(frappe.db.escape(company)) - data = frappe.db.sql(""" SELECT party, sum({0}) as amount - FROM `tabGL Entry` + data = frappe.db.sql(""" SELECT gle.party, sum(gle.{0}) as amount + FROM `tabGL Entry` gle + INNER JOIN `tabPayment Entry` pe ON pe.name = gle.voucher_no WHERE - party_type = %s and against_voucher is null - and {1} GROUP BY party""" + gle.party_type = %s and gle.against_voucher is null + and pe.docstatus = 1 + and {1} GROUP BY gle.party""" .format(("credit") if party_type == "Customer" else "debit", cond) , party_type) if data: From 810a36105ca10d555e7f92c3870199cf5af98710 Mon Sep 17 00:00:00 2001 From: UrvashiKishnani <41088003+UrvashiKishnani@users.noreply.github.com> Date: Tue, 2 Mar 2021 08:20:03 +0400 Subject: [PATCH 2/2] fix: GL Entries for AP/AR Summary without SQL join SQL query modified to fetch only those GL Entries for Accounts Payable Summary and Accounts Receivable Summary reports where the corresponding payment entry is not in cancelled state. --- erpnext/accounts/party.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 7d53db2dc37..e01cb6e151e 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -606,20 +606,19 @@ def get_partywise_advanced_payment_amount(party_type, posting_date = None, futur cond = "1=1" if posting_date: if future_payment: - cond = "gle.posting_date <= '{0}' OR DATE(creation) <= '{0}' """.format(posting_date) + cond = "posting_date <= '{0}' OR DATE(creation) <= '{0}' """.format(posting_date) else: - cond = "gle.posting_date <= '{0}'".format(posting_date) + cond = "posting_date <= '{0}'".format(posting_date) if company: - cond += "and gle.company = {0}".format(frappe.db.escape(company)) + cond += "and company = {0}".format(frappe.db.escape(company)) - data = frappe.db.sql(""" SELECT gle.party, sum(gle.{0}) as amount - FROM `tabGL Entry` gle - INNER JOIN `tabPayment Entry` pe ON pe.name = gle.voucher_no + data = frappe.db.sql(""" SELECT party, sum({0}) as amount + FROM `tabGL Entry` WHERE - gle.party_type = %s and gle.against_voucher is null - and pe.docstatus = 1 - and {1} GROUP BY gle.party""" + party_type = %s and against_voucher is null + and is_cancelled = 0 + and {1} GROUP BY party""" .format(("credit") if party_type == "Customer" else "debit", cond) , party_type) if data: