From 59f4fa9a8c9f769a8994e46d43e8de345bba3765 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 17 Sep 2015 13:57:42 +0530 Subject: [PATCH] [fix] Account Currency and Balance fixed in chart of accounts #4019 --- .../page/accounts_browser/accounts_browser.js | 2 +- .../page/accounts_browser/accounts_browser.py | 13 +++++-------- erpnext/accounts/utils.py | 5 +++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/page/accounts_browser/accounts_browser.js b/erpnext/accounts/page/accounts_browser/accounts_browser.js index 04e4f6354b..abd7612ce0 100644 --- a/erpnext/accounts/page/accounts_browser/accounts_browser.js +++ b/erpnext/accounts/page/accounts_browser/accounts_browser.js @@ -166,7 +166,7 @@ erpnext.AccountsChart = Class.extend({ var dr_or_cr = node.data.balance < 0 ? "Cr" : "Dr"; if (me.ctype == 'Account' && node.data && node.data.balance!==undefined) { $('' - + format_currency(Math.abs(node.data.balance), node.data.currency) + + format_currency(Math.abs(node.data.balance), node.data.account_currency) + " " + dr_or_cr + '').insertBefore(node.$ul); } diff --git a/erpnext/accounts/page/accounts_browser/accounts_browser.py b/erpnext/accounts/page/accounts_browser/accounts_browser.py index 593794a5cb..80101ce0c5 100644 --- a/erpnext/accounts/page/accounts_browser/accounts_browser.py +++ b/erpnext/accounts/page/accounts_browser/accounts_browser.py @@ -21,8 +21,7 @@ def get_children(): # root if args['parent'] in ("Accounts", "Cost Centers"): - select_cond = ", root_type, report_type" if args["parent"]=="Accounts" else "" - + select_cond = ", root_type, report_type, account_currency" if ctype=="Account" else "" acc = frappe.db.sql(""" select name as value, is_group as expandable %s from `tab%s` @@ -35,19 +34,17 @@ def get_children(): sort_root_accounts(acc) else: # other + select_cond = ", account_currency" if ctype=="Account" else "" acc = frappe.db.sql("""select - name as value, is_group as expandable + name as value, is_group as expandable %s from `tab%s` where ifnull(parent_%s,'') = %s and docstatus<2 - order by name""" % (ctype, ctype.lower().replace(' ','_'), '%s'), + order by name""" % (select_cond, ctype, ctype.lower().replace(' ','_'), '%s'), args['parent'], as_dict=1) if ctype == 'Account': - currency = frappe.db.sql("select default_currency from `tabCompany` where name = %s", company)[0][0] for each in acc: - bal = get_balance_on(each.get("value")) - each["currency"] = currency - each["balance"] = flt(bal) + each["balance"] = flt(get_balance_on(each.get("value"))) return acc diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index e1bb9ead33..04084ed0e8 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -94,6 +94,11 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, in_acco select name from `tabAccount` ac where ac.name = gle.account and ac.lft >= %s and ac.rgt <= %s )""" % (acc.lft, acc.rgt)) + + # If group and currency same as company, + # always return balance based on debit and credit in company currency + if acc.account_currency == frappe.db.get_value("Company", acc.company, "default_currency"): + in_account_currency = False else: cond.append("""gle.account = "%s" """ % (account.replace('"', '\\"'), ))