From 8c21703959075c464ad9772aa90435e3eaab64a1 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 16 Jul 2019 09:41:01 +0530 Subject: [PATCH] fix: Fixes in get_balance_on function (#18324) --- erpnext/accounts/utils.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index e75dd957db..e41c74cac8 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -104,6 +104,9 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, company # get balance of all entries that exist date = nowdate() + if account: + acc = frappe.get_doc("Account", account) + try: year_start_date = get_fiscal_year(date, verbose=0)[1] except FiscalYearError: @@ -118,7 +121,7 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, company allow_cost_center_in_entry_of_bs_account = get_allow_cost_center_in_entry_of_bs_account() - if cost_center and allow_cost_center_in_entry_of_bs_account: + if cost_center and (allow_cost_center_in_entry_of_bs_account or acc.report_type =='Profit and Loss'): cc = frappe.get_doc("Cost Center", cost_center) if cc.is_group: cond.append(""" exists ( @@ -132,20 +135,13 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, company if account: - acc = frappe.get_doc("Account", account) - if not frappe.flags.ignore_account_permission: acc.check_permission("read") - - if not allow_cost_center_in_entry_of_bs_account and acc.report_type == 'Profit and Loss': + if acc.report_type == 'Profit and Loss': # for pl accounts, get balance within a fiscal year cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \ % year_start_date) - elif allow_cost_center_in_entry_of_bs_account: - # for all accounts, get balance within a fiscal year if maintain cost center in balance account is checked - cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \ - % year_start_date) # different filter for group and ledger - improved performance if acc.is_group: cond.append("""exists (