fix: Show GL balance in Accounts Receivable and payable summary

(cherry picked from commit 1d270dca05501b5a15d19e3270188029b48eafde)

# Conflicts:
#	erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
This commit is contained in:
Deepesh Garg 2022-01-04 17:53:08 +05:30 committed by mergify-bot
parent f6f449ed18
commit bf5930c4bb
2 changed files with 29 additions and 0 deletions

View File

@ -117,6 +117,11 @@ frappe.query_reports["Accounts Receivable Summary"] = {
"label": __("Show Future Payments"), "label": __("Show Future Payments"),
"fieldtype": "Check", "fieldtype": "Check",
}, },
{
"fieldname":"show_gl_balance",
"label": __("Show GL Balance"),
"fieldtype": "Check",
},
], ],
onload: function(report) { onload: function(report) {

View File

@ -4,7 +4,12 @@
import frappe import frappe
from frappe import _, scrub from frappe import _, scrub
<<<<<<< HEAD
from frappe.utils import cint from frappe.utils import cint
=======
from frappe.utils import cint, flt
from six import iteritems
>>>>>>> 1d270dca05 (fix: Show GL balance in Accounts Receivable and payable summary)
from erpnext.accounts.party import get_partywise_advanced_payment_amount from erpnext.accounts.party import get_partywise_advanced_payment_amount
from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport
@ -36,7 +41,14 @@ class AccountsReceivableSummary(ReceivablePayableReport):
party_advance_amount = get_partywise_advanced_payment_amount(self.party_type, party_advance_amount = get_partywise_advanced_payment_amount(self.party_type,
self.filters.report_date, self.filters.show_future_payments, self.filters.company) or {} self.filters.report_date, self.filters.show_future_payments, self.filters.company) or {}
<<<<<<< HEAD
for party, party_dict in self.party_total.items(): for party, party_dict in self.party_total.items():
=======
if self.filters.show_gl_balance:
gl_balance_map = get_gl_balance(self.filters.report_date)
for party, party_dict in iteritems(self.party_total):
>>>>>>> 1d270dca05 (fix: Show GL balance in Accounts Receivable and payable summary)
if party_dict.outstanding == 0: if party_dict.outstanding == 0:
continue continue
@ -55,6 +67,10 @@ class AccountsReceivableSummary(ReceivablePayableReport):
# but in summary report advance shown in separate column # but in summary report advance shown in separate column
row.paid -= row.advance row.paid -= row.advance
if self.filters.show_gl_balance:
row.gl_balance = gl_balance_map.get(party)
row.diff = flt(row.outstanding) - flt(row.gl_balance)
self.data.append(row) self.data.append(row)
def get_party_total(self, args): def get_party_total(self, args):
@ -114,6 +130,10 @@ class AccountsReceivableSummary(ReceivablePayableReport):
self.add_column(_(credit_debit_label), fieldname='credit_note') self.add_column(_(credit_debit_label), fieldname='credit_note')
self.add_column(_('Outstanding Amount'), fieldname='outstanding') self.add_column(_('Outstanding Amount'), fieldname='outstanding')
if self.filters.show_gl_balance:
self.add_column(_('GL Balance'), fieldname='gl_balance')
self.add_column(_('Difference'), fieldname='diff')
self.setup_ageing_columns() self.setup_ageing_columns()
if self.party_type == "Customer": if self.party_type == "Customer":
@ -140,3 +160,7 @@ class AccountsReceivableSummary(ReceivablePayableReport):
# Add column for total due amount # Add column for total due amount
self.add_column(label="Total Amount Due", fieldname='total_due') self.add_column(label="Total Amount Due", fieldname='total_due')
def get_gl_balance(report_date):
return frappe._dict(frappe.db.get_all("GL Entry", fields=['party', 'sum(debit - credit)'],
filters={'posting_date': ("<=", report_date), 'is_cancelled': 0}, group_by='party', as_list=1))