Code optimization for consolidated financial statement report
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
index 10940c3..b9aebd8 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
@@ -331,13 +331,18 @@
 		filters.get('company'),  ["lft", "rgt"])
 
 	additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters)
-	companies = frappe.db.sql_list(""" select name from `tabCompany`
+	companies = frappe.db.sql(""" select name, default_currency from `tabCompany`
 		where lft >= %(company_lft)s and rgt <= %(company_rgt)s""", {
 			"company_lft": company_lft,
 			"company_rgt": company_rgt,
-		})
+		}, as_dict=1)
 
-	for company in companies:
+	currency_info = frappe._dict({
+		'report_date': to_date,
+		'presentation_currency': filters.get('presentation_currency')
+	})
+
+	for d in companies:
 		gl_entries = frappe.db.sql("""select gl.posting_date, gl.account, gl.debit, gl.credit, gl.is_opening, gl.company,
 			gl.fiscal_year, gl.debit_in_account_currency, gl.credit_in_account_currency, gl.account_currency,
 			acc.account_name, acc.account_number
@@ -349,13 +354,14 @@
 				"to_date": to_date,
 				"lft": root_lft,
 				"rgt": root_rgt,
-				"company": company
+				"company": d.name
 			},
 			as_dict=True)
 
-		if filters and filters.get('presentation_currency'):
-			filters['company'] = company
-			convert_to_presentation_currency(gl_entries, get_currency(filters))
+		if filters and filters.get('presentation_currency') != d.default_currency:
+			currency_info['company'] = d.name
+			currency_info['company_currency'] = d.default_currency
+			convert_to_presentation_currency(gl_entries, currency_info)
 
 		for entry in gl_entries:
 			key = entry.account_number or entry.account_name