Merge pull request #4962 from nabinhait/trial_balance_fix
[fix] Trial Balance report, showing rows with zero values
This commit is contained in:
commit
f0e16e68c5
@ -170,17 +170,19 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def filter_out_zero_value_rows(data, parent_children_map):
|
def filter_out_zero_value_rows(data, parent_children_map, show_zero_values=False):
|
||||||
data_with_value = []
|
data_with_value = []
|
||||||
for d in data:
|
for d in data:
|
||||||
if d.get("has_value"):
|
if show_zero_values or d.get("has_value"):
|
||||||
data_with_value.append(d)
|
data_with_value.append(d)
|
||||||
else:
|
else:
|
||||||
children = [child.name for child in parent_children_map.get(d.account) or []]
|
# show group with zero balance, if there are balances against child
|
||||||
for row in data:
|
children = [child.name for child in parent_children_map.get(d.get("account")) or []]
|
||||||
if row.account in children and row.get("has_value"):
|
if children:
|
||||||
data_with_value.append(d)
|
for row in data:
|
||||||
break
|
if row.get("account") in children and row.get("has_value"):
|
||||||
|
data_with_value.append(d)
|
||||||
|
break
|
||||||
|
|
||||||
return data_with_value
|
return data_with_value
|
||||||
|
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint, flt, getdate, formatdate, cstr
|
from frappe.utils import flt, getdate, formatdate, cstr
|
||||||
from erpnext.accounts.report.financial_statements import filter_accounts, set_gl_entries_by_account
|
from erpnext.accounts.report.financial_statements \
|
||||||
|
import filter_accounts, set_gl_entries_by_account, filter_out_zero_value_rows
|
||||||
|
|
||||||
value_fields = ("opening_debit", "opening_credit", "debit", "credit", "closing_debit", "closing_credit")
|
value_fields = ("opening_debit", "opening_credit", "debit", "credit", "closing_debit", "closing_credit")
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ def get_data(filters):
|
|||||||
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)
|
||||||
|
|
||||||
min_lft, max_rgt = frappe.db.sql("""select min(lft), max(rgt) from `tabAccount`
|
min_lft, max_rgt = frappe.db.sql("""select min(lft), max(rgt) from `tabAccount`
|
||||||
where company=%s""", (filters.company,))[0]
|
where company=%s""", (filters.company,))[0]
|
||||||
@ -71,7 +72,9 @@ def get_data(filters):
|
|||||||
total_row = calculate_values(accounts, gl_entries_by_account, opening_balances, filters)
|
total_row = calculate_values(accounts, gl_entries_by_account, opening_balances, filters)
|
||||||
accumulate_values_into_parents(accounts, accounts_by_name)
|
accumulate_values_into_parents(accounts, accounts_by_name)
|
||||||
|
|
||||||
data = prepare_data(accounts, filters, total_row)
|
data = prepare_data(accounts, filters, total_row, parent_children_map)
|
||||||
|
data = filter_out_zero_value_rows(data, parent_children_map,
|
||||||
|
show_zero_values=filters.get("show_zero_values"))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -156,10 +159,8 @@ def accumulate_values_into_parents(accounts, accounts_by_name):
|
|||||||
for key in value_fields:
|
for key in value_fields:
|
||||||
accounts_by_name[d.parent_account][key] += d[key]
|
accounts_by_name[d.parent_account][key] += d[key]
|
||||||
|
|
||||||
def prepare_data(accounts, filters, total_row):
|
def prepare_data(accounts, filters, total_row, parent_children_map):
|
||||||
show_zero_values = cint(filters.show_zero_values)
|
|
||||||
data = []
|
data = []
|
||||||
accounts_with_zero_value = []
|
|
||||||
for d in accounts:
|
for d in accounts:
|
||||||
has_value = False
|
has_value = False
|
||||||
row = {
|
row = {
|
||||||
@ -174,17 +175,14 @@ def prepare_data(accounts, filters, total_row):
|
|||||||
prepare_opening_and_closing(d)
|
prepare_opening_and_closing(d)
|
||||||
|
|
||||||
for key in value_fields:
|
for key in value_fields:
|
||||||
row[key] = d.get(key, 0.0)
|
row[key] = flt(d.get(key, 0.0), 3)
|
||||||
if row[key]:
|
|
||||||
|
if abs(row[key]) >= 0.005:
|
||||||
|
# ignore zero values
|
||||||
has_value = True
|
has_value = True
|
||||||
|
|
||||||
if show_zero_values:
|
row["has_value"] = has_value
|
||||||
data.append(row)
|
data.append(row)
|
||||||
else:
|
|
||||||
if not has_value:
|
|
||||||
accounts_with_zero_value.append(d.name)
|
|
||||||
elif d.parent_account not in accounts_with_zero_value:
|
|
||||||
data.append(row)
|
|
||||||
|
|
||||||
data.extend([{},total_row])
|
data.extend([{},total_row])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user