From c78b92141293a40c7e42ae6c10c9d9e469291522 Mon Sep 17 00:00:00 2001 From: bghayad Date: Wed, 15 May 2019 09:28:59 +0300 Subject: [PATCH] Fix for Chart of Account sorting problem (#17563) * First Commit from Master * Fix for CoA sorting problem * Fixing for CoA sorting problem * Fix for Chart of Account Sorting Problem --- erpnext/accounts/report/financial_statements.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index d26aeb11b9e..fe030c5f1ce 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -321,7 +321,10 @@ def sort_accounts(accounts, is_root=False, key="name"): """Sort root types as Asset, Liability, Equity, Income, Expense""" def compare_accounts(a, b): - if is_root: + if re.split('\W+', a[key])[0].isdigit(): + # if chart of accounts is numbered, then sort by number + return cmp(a[key], b[key]) + elif is_root: 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": @@ -330,10 +333,6 @@ def sort_accounts(accounts, is_root=False, key="name"): return -1 if a.root_type == "Income" and b.root_type == "Expense": return -1 - else: - if re.split('\W+', a[key])[0].isdigit(): - # if chart of accounts is numbered, then sort by number - return cmp(a[key], b[key]) return 1 accounts.sort(key = functools.cmp_to_key(compare_accounts))