From 6799e27390802a1b5e0b8d4b0a0ca04bef361e61 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 18 May 2017 16:21:21 +0530 Subject: [PATCH] [fix] chart of accounts root sorting, #8784, #8897 (#8904) --- erpnext/accounts/report/financial_statements.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 41d0e48a772..f6a032cb456 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 @@ def sort_root_accounts(roots): """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":