Merge pull request #4029 from nabinhait/mc2

[fix] Account Currency and Balance fixed in chart of accounts #4019
This commit is contained in:
Anand Doshi 2015-09-17 14:37:00 +05:30
commit 70fed64cd5
3 changed files with 11 additions and 9 deletions

View File

@ -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) {
$('<span class="balance-area pull-right text-muted small">'
+ format_currency(Math.abs(node.data.balance), node.data.currency)
+ format_currency(Math.abs(node.data.balance), node.data.account_currency)
+ " " + dr_or_cr
+ '</span>').insertBefore(node.$ul);
}

View File

@ -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

View File

@ -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('"', '\\"'), ))