[fix][report] Show group rows with zero values if there are values against children
This commit is contained in:
parent
a0b21235d7
commit
acb28954ff
@ -19,7 +19,7 @@ def execute(filters=None):
|
|||||||
|
|
||||||
data = []
|
data = []
|
||||||
data.extend(asset or [])
|
data.extend(asset or [])
|
||||||
data.extend(liability or [])
|
data.extend(liability or [])
|
||||||
data.extend(equity or [])
|
data.extend(equity or [])
|
||||||
if provisional_profit_loss:
|
if provisional_profit_loss:
|
||||||
data.append(provisional_profit_loss)
|
data.append(provisional_profit_loss)
|
||||||
@ -43,11 +43,11 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company):
|
|||||||
for period in period_list:
|
for period in period_list:
|
||||||
effective_liability = 0.0
|
effective_liability = 0.0
|
||||||
if liability:
|
if liability:
|
||||||
effective_liability += flt(liability[-2][period.key])
|
effective_liability += flt(liability[-2].get(period.key))
|
||||||
if equity:
|
if equity:
|
||||||
effective_liability += flt(equity[-2][period.key])
|
effective_liability += flt(equity[-2].get(period.key))
|
||||||
|
|
||||||
provisional_profit_loss[period.key] = flt(asset[-2][period.key]) - effective_liability
|
provisional_profit_loss[period.key] = flt(asset[-2].get(period.key)) - effective_liability
|
||||||
|
|
||||||
if provisional_profit_loss[period.key]:
|
if provisional_profit_loss[period.key]:
|
||||||
has_value = True
|
has_value = True
|
||||||
|
@ -92,7 +92,7 @@ def get_data(company, root_type, balance_must_be, period_list,
|
|||||||
if not accounts:
|
if not accounts:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
accounts, accounts_by_name = filter_accounts(accounts)
|
accounts, accounts_by_name, parent_children_map = filter_accounts(accounts)
|
||||||
|
|
||||||
company_currency = frappe.db.get_value("Company", company, "default_currency")
|
company_currency = frappe.db.get_value("Company", company, "default_currency")
|
||||||
|
|
||||||
@ -109,6 +109,7 @@ def get_data(company, root_type, balance_must_be, period_list,
|
|||||||
calculate_values(accounts_by_name, gl_entries_by_account, period_list, accumulated_values)
|
calculate_values(accounts_by_name, gl_entries_by_account, period_list, accumulated_values)
|
||||||
accumulate_values_into_parents(accounts, accounts_by_name, period_list, accumulated_values)
|
accumulate_values_into_parents(accounts, accounts_by_name, period_list, accumulated_values)
|
||||||
out = prepare_data(accounts, balance_must_be, period_list, company_currency)
|
out = prepare_data(accounts, balance_must_be, period_list, company_currency)
|
||||||
|
out = filter_out_zero_value_rows(out, parent_children_map)
|
||||||
|
|
||||||
if out:
|
if out:
|
||||||
add_total_row(out, balance_must_be, period_list, company_currency)
|
add_total_row(out, balance_must_be, period_list, company_currency)
|
||||||
@ -134,15 +135,15 @@ def accumulate_values_into_parents(accounts, accounts_by_name, period_list, accu
|
|||||||
d.get(period.key, 0.0)
|
d.get(period.key, 0.0)
|
||||||
|
|
||||||
def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
||||||
out = []
|
data = []
|
||||||
year_start_date = period_list[0]["year_start_date"].strftime("%Y-%m-%d")
|
year_start_date = period_list[0]["year_start_date"].strftime("%Y-%m-%d")
|
||||||
year_end_date = period_list[-1]["year_end_date"].strftime("%Y-%m-%d")
|
year_end_date = period_list[-1]["year_end_date"].strftime("%Y-%m-%d")
|
||||||
|
|
||||||
for d in accounts:
|
for d in accounts:
|
||||||
# add to output
|
# add to output
|
||||||
has_value = False
|
has_value = False
|
||||||
total = 0
|
total = 0
|
||||||
row = {
|
row = frappe._dict({
|
||||||
"account_name": d.account_name,
|
"account_name": d.account_name,
|
||||||
"account": d.name,
|
"account": d.name,
|
||||||
"parent_account": d.parent_account,
|
"parent_account": d.parent_account,
|
||||||
@ -150,7 +151,7 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
|||||||
"year_start_date": year_start_date,
|
"year_start_date": year_start_date,
|
||||||
"year_end_date": year_end_date,
|
"year_end_date": year_end_date,
|
||||||
"currency": company_currency
|
"currency": company_currency
|
||||||
}
|
})
|
||||||
for period in period_list:
|
for period in period_list:
|
||||||
if d.get(period.key):
|
if d.get(period.key):
|
||||||
# change sign based on Debit or Credit, since calculation is done using (debit - credit)
|
# change sign based on Debit or Credit, since calculation is done using (debit - credit)
|
||||||
@ -163,11 +164,25 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
|||||||
has_value = True
|
has_value = True
|
||||||
total += flt(row[period.key])
|
total += flt(row[period.key])
|
||||||
|
|
||||||
if has_value:
|
row["has_value"] = has_value
|
||||||
row["total"] = total
|
row["total"] = total
|
||||||
out.append(row)
|
data.append(row)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def filter_out_zero_value_rows(data, parent_children_map):
|
||||||
|
data_with_value = []
|
||||||
|
for d in data:
|
||||||
|
if d.get("has_value"):
|
||||||
|
data_with_value.append(d)
|
||||||
|
else:
|
||||||
|
children = [child.name for child in parent_children_map.get(d.account) or []]
|
||||||
|
for row in data:
|
||||||
|
if row.account in children and row.get("has_value"):
|
||||||
|
data_with_value.append(d)
|
||||||
|
break
|
||||||
|
|
||||||
return out
|
return data_with_value
|
||||||
|
|
||||||
def add_total_row(out, balance_must_be, period_list, company_currency):
|
def add_total_row(out, balance_must_be, period_list, company_currency):
|
||||||
total_row = {
|
total_row = {
|
||||||
@ -187,10 +202,11 @@ def add_total_row(out, balance_must_be, period_list, company_currency):
|
|||||||
total_row["total"] += flt(row["total"])
|
total_row["total"] += flt(row["total"])
|
||||||
row["total"] = ""
|
row["total"] = ""
|
||||||
|
|
||||||
out.append(total_row)
|
if total_row.has_key("total"):
|
||||||
|
out.append(total_row)
|
||||||
|
|
||||||
# blank row after Total
|
# blank row after Total
|
||||||
out.append({})
|
out.append({})
|
||||||
|
|
||||||
def get_accounts(company, root_type):
|
def get_accounts(company, root_type):
|
||||||
return frappe.db.sql("""select name, parent_account, lft, rgt, root_type, report_type, account_name from `tabAccount`
|
return frappe.db.sql("""select name, parent_account, lft, rgt, root_type, report_type, account_name from `tabAccount`
|
||||||
@ -218,7 +234,7 @@ def filter_accounts(accounts, depth=10):
|
|||||||
|
|
||||||
add_to_list(None, 0)
|
add_to_list(None, 0)
|
||||||
|
|
||||||
return filtered_accounts, accounts_by_name
|
return filtered_accounts, accounts_by_name, parent_children_map
|
||||||
|
|
||||||
def sort_root_accounts(roots):
|
def sort_root_accounts(roots):
|
||||||
"""Sort root types as Asset, Liability, Equity, Income, Expense"""
|
"""Sort root types as Asset, Liability, Equity, Income, Expense"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user