fix: Fixes in get_balance_on function (#18324)
This commit is contained in:
parent
82770d9152
commit
8c21703959
@ -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
|
# get balance of all entries that exist
|
||||||
date = nowdate()
|
date = nowdate()
|
||||||
|
|
||||||
|
if account:
|
||||||
|
acc = frappe.get_doc("Account", account)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
year_start_date = get_fiscal_year(date, verbose=0)[1]
|
year_start_date = get_fiscal_year(date, verbose=0)[1]
|
||||||
except FiscalYearError:
|
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()
|
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)
|
cc = frappe.get_doc("Cost Center", cost_center)
|
||||||
if cc.is_group:
|
if cc.is_group:
|
||||||
cond.append(""" exists (
|
cond.append(""" exists (
|
||||||
@ -132,20 +135,13 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, company
|
|||||||
|
|
||||||
if account:
|
if account:
|
||||||
|
|
||||||
acc = frappe.get_doc("Account", account)
|
|
||||||
|
|
||||||
if not frappe.flags.ignore_account_permission:
|
if not frappe.flags.ignore_account_permission:
|
||||||
acc.check_permission("read")
|
acc.check_permission("read")
|
||||||
|
|
||||||
|
if acc.report_type == 'Profit and Loss':
|
||||||
if not allow_cost_center_in_entry_of_bs_account and acc.report_type == 'Profit and Loss':
|
|
||||||
# for pl accounts, get balance within a fiscal year
|
# for pl accounts, get balance within a fiscal year
|
||||||
cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \
|
cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \
|
||||||
% year_start_date)
|
% 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
|
# different filter for group and ledger - improved performance
|
||||||
if acc.is_group:
|
if acc.is_group:
|
||||||
cond.append("""exists (
|
cond.append("""exists (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user