fix: SQL query in financial statements
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 96f78f9..35915d0 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -350,39 +350,40 @@
accounts = frappe.db.sql_list("""select name from `tabAccount`
where lft >= %s and rgt <= %s and company = %s""", (root_lft, root_rgt, company))
- additional_conditions += " and account in ({})"\
- .format(", ".join([frappe.db.escape(d) for d in accounts]))
+ if accounts:
+ additional_conditions += " and account in ({})"\
+ .format(", ".join([frappe.db.escape(d) for d in accounts]))
- gl_filters = {
- "company": company,
- "from_date": from_date,
- "to_date": to_date,
- "finance_book": cstr(filters.get("finance_book"))
- }
+ gl_filters = {
+ "company": company,
+ "from_date": from_date,
+ "to_date": to_date,
+ "finance_book": cstr(filters.get("finance_book"))
+ }
- if filters.get("include_default_book_entries"):
- gl_filters["company_fb"] = frappe.db.get_value("Company",
- company, 'default_finance_book')
+ if filters.get("include_default_book_entries"):
+ gl_filters["company_fb"] = frappe.db.get_value("Company",
+ company, 'default_finance_book')
- for key, value in filters.items():
- if value:
- gl_filters.update({
- key: value
- })
+ for key, value in filters.items():
+ if value:
+ gl_filters.update({
+ key: value
+ })
- gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry`
- where company=%(company)s
- {additional_conditions}
- and posting_date <= %(to_date)s
- order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) #nosec
+ gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry`
+ where company=%(company)s
+ {additional_conditions}
+ and posting_date <= %(to_date)s
+ order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) #nosec
- if filters and filters.get('presentation_currency'):
- convert_to_presentation_currency(gl_entries, get_currency(filters))
+ if filters and filters.get('presentation_currency'):
+ convert_to_presentation_currency(gl_entries, get_currency(filters))
- for entry in gl_entries:
- gl_entries_by_account.setdefault(entry.account, []).append(entry)
+ for entry in gl_entries:
+ gl_entries_by_account.setdefault(entry.account, []).append(entry)
- return gl_entries_by_account
+ return gl_entries_by_account
def get_additional_conditions(from_date, ignore_closing_entries, filters):