fix(trial balance): Show opening and closing of group account in single column (#19511)

This commit is contained in:
Nabin Hait
2019-11-11 10:59:30 +05:30
committed by GitHub
parent dbcdf7e225
commit d2dc889849

View File

@@ -75,8 +75,7 @@ def get_data(filters):
accumulate_values_into_parents(accounts, accounts_by_name) accumulate_values_into_parents(accounts, accounts_by_name)
data = prepare_data(accounts, filters, total_row, parent_children_map, company_currency) data = prepare_data(accounts, filters, total_row, parent_children_map, company_currency)
data = filter_out_zero_value_rows(data, parent_children_map, data = filter_out_zero_value_rows(data, parent_children_map, show_zero_values=filters.get("show_zero_values"))
show_zero_values=filters.get("show_zero_values"))
return data return data
@@ -175,33 +174,11 @@ def calculate_values(accounts, gl_entries_by_account, opening_balances, filters,
d["closing_debit"] = d["opening_debit"] + d["debit"] d["closing_debit"] = d["opening_debit"] + d["debit"]
d["closing_credit"] = d["opening_credit"] + d["credit"] d["closing_credit"] = d["opening_credit"] + d["credit"]
total_row["debit"] += d["debit"]
total_row["credit"] += d["credit"]
if d["root_type"] == "Asset" or d["root_type"] == "Equity" or d["root_type"] == "Expense": prepare_opening_closing(d)
d["opening_debit"] -= d["opening_credit"]
d["closing_debit"] -= d["closing_credit"]
# For opening for field in value_fields:
check_opening_closing_has_negative_value(d, "opening_debit", "opening_credit") total_row[field] += d[field]
# For closing
check_opening_closing_has_negative_value(d, "closing_debit", "closing_credit")
if d["root_type"] == "Liability" or d["root_type"] == "Income":
d["opening_credit"] -= d["opening_debit"]
d["closing_credit"] -= d["closing_debit"]
# For opening
check_opening_closing_has_negative_value(d, "opening_credit", "opening_debit")
# For closing
check_opening_closing_has_negative_value(d, "closing_credit", "closing_debit")
total_row["opening_debit"] += d["opening_debit"]
total_row["closing_debit"] += d["closing_debit"]
total_row["opening_credit"] += d["opening_credit"]
total_row["closing_credit"] += d["closing_credit"]
return total_row return total_row
@@ -215,6 +192,10 @@ def prepare_data(accounts, filters, total_row, parent_children_map, company_curr
data = [] data = []
for d in accounts: for d in accounts:
# Prepare opening closing for group account
if parent_children_map.get(d.account):
prepare_opening_closing(d)
has_value = False has_value = False
row = { row = {
"account": d.name, "account": d.name,
@@ -301,11 +282,16 @@ def get_columns():
} }
] ]
def check_opening_closing_has_negative_value(d, dr_or_cr, switch_to_column): def prepare_opening_closing(row):
# If opening debit has negetive value then move it to opening credit and vice versa. dr_or_cr = "debit" if row["root_type"] in ["Asset", "Equity", "Expense"] else "credit"
reverse_dr_or_cr = "credit" if dr_or_cr == "debit" else "debit"
if d[dr_or_cr] < 0: for col_type in ["opening", "closing"]:
d[switch_to_column] = abs(d[dr_or_cr]) valid_col = col_type + "_" + dr_or_cr
d[dr_or_cr] = 0.0 reverse_col = col_type + "_" + reverse_dr_or_cr
else: row[valid_col] -= row[reverse_col]
d[switch_to_column] = 0.0 if row[valid_col] < 0:
row[reverse_col] = abs(row[valid_col])
row[valid_col] = 0.0
else:
row[reverse_col] = 0.0