[fix] chart of accounts root sorting, #8784, #8897 (#8904)
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 41d0e48..f6a032c 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -3,6 +3,7 @@
from __future__ import unicode_literals
import frappe
+import re
from frappe import _
from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff,
add_months, add_days, formatdate, cint)
@@ -277,6 +278,9 @@
"""Sort root types as Asset, Liability, Equity, Income, Expense"""
def compare_roots(a, b):
+ if re.split('\W+', a.value)[0].isdigit():
+ # if chart of accounts is numbered, then sort by number
+ return cmp(a.value, b.value)
if a.report_type != b.report_type and a.report_type == "Balance Sheet":
return -1
if a.root_type != b.root_type and a.root_type == "Asset":