fix: Cost center filter not working in cash flow report
This commit is contained in:
parent
b179514273
commit
d0dbfec052
@ -8,6 +8,7 @@ from frappe.utils import cint, cstr
|
|||||||
|
|
||||||
from erpnext.accounts.report.financial_statements import (
|
from erpnext.accounts.report.financial_statements import (
|
||||||
get_columns,
|
get_columns,
|
||||||
|
get_cost_centers_with_children,
|
||||||
get_data,
|
get_data,
|
||||||
get_filtered_list_for_consolidated_report,
|
get_filtered_list_for_consolidated_report,
|
||||||
get_period_list,
|
get_period_list,
|
||||||
@ -160,10 +161,11 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
|||||||
total = 0
|
total = 0
|
||||||
for period in period_list:
|
for period in period_list:
|
||||||
start_date = get_start_date(period, accumulated_values, company)
|
start_date = get_start_date(period, accumulated_values, company)
|
||||||
|
filters.start_date = start_date
|
||||||
|
filters.end_date = period["to_date"]
|
||||||
|
filters.account_type = account_type
|
||||||
|
|
||||||
amount = get_account_type_based_gl_data(
|
amount = get_account_type_based_gl_data(company, filters)
|
||||||
company, start_date, period["to_date"], account_type, filters
|
|
||||||
)
|
|
||||||
|
|
||||||
if amount and account_type == "Depreciation":
|
if amount and account_type == "Depreciation":
|
||||||
amount *= -1
|
amount *= -1
|
||||||
@ -175,7 +177,7 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters=None):
|
def get_account_type_based_gl_data(company, filters=None):
|
||||||
cond = ""
|
cond = ""
|
||||||
filters = frappe._dict(filters or {})
|
filters = frappe._dict(filters or {})
|
||||||
|
|
||||||
@ -191,19 +193,25 @@ def get_account_type_based_gl_data(company, start_date, end_date, account_type,
|
|||||||
frappe.db.escape(cstr(filters.finance_book))
|
frappe.db.escape(cstr(filters.finance_book))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if filters.get("cost_center"):
|
||||||
|
filters.cost_center = get_cost_centers_with_children(filters.cost_center)
|
||||||
|
cond += " and cost_center in %(cost_center)s"
|
||||||
|
|
||||||
gl_sum = frappe.db.sql_list(
|
gl_sum = frappe.db.sql_list(
|
||||||
"""
|
"""
|
||||||
select sum(credit) - sum(debit)
|
select sum(credit) - sum(debit)
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where company=%s and posting_date >= %s and posting_date <= %s
|
where company=%(company)s and posting_date >= %(start_date)s and posting_date <= %(end_date)s
|
||||||
and voucher_type != 'Period Closing Voucher'
|
and voucher_type != 'Period Closing Voucher'
|
||||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %s) {cond}
|
and account in ( SELECT name FROM tabAccount WHERE account_type = %(account_type)s) {cond}
|
||||||
""".format(
|
""".format(
|
||||||
cond=cond
|
cond=cond
|
||||||
),
|
),
|
||||||
(company, start_date, end_date, account_type),
|
filters,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(gl_sum)
|
||||||
|
|
||||||
return gl_sum[0] if gl_sum and gl_sum[0] else 0
|
return gl_sum[0] if gl_sum and gl_sum[0] else 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user