fix: SQL query in financial statements
This commit is contained in:
parent
d8e57d3d5a
commit
30e766b228
@ -350,39 +350,40 @@ def set_gl_entries_by_account(
|
|||||||
accounts = frappe.db.sql_list("""select name from `tabAccount`
|
accounts = frappe.db.sql_list("""select name from `tabAccount`
|
||||||
where lft >= %s and rgt <= %s and company = %s""", (root_lft, root_rgt, company))
|
where lft >= %s and rgt <= %s and company = %s""", (root_lft, root_rgt, company))
|
||||||
|
|
||||||
additional_conditions += " and account in ({})"\
|
if accounts:
|
||||||
.format(", ".join([frappe.db.escape(d) for d in accounts]))
|
additional_conditions += " and account in ({})"\
|
||||||
|
.format(", ".join([frappe.db.escape(d) for d in accounts]))
|
||||||
|
|
||||||
gl_filters = {
|
gl_filters = {
|
||||||
"company": company,
|
"company": company,
|
||||||
"from_date": from_date,
|
"from_date": from_date,
|
||||||
"to_date": to_date,
|
"to_date": to_date,
|
||||||
"finance_book": cstr(filters.get("finance_book"))
|
"finance_book": cstr(filters.get("finance_book"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.get("include_default_book_entries"):
|
if filters.get("include_default_book_entries"):
|
||||||
gl_filters["company_fb"] = frappe.db.get_value("Company",
|
gl_filters["company_fb"] = frappe.db.get_value("Company",
|
||||||
company, 'default_finance_book')
|
company, 'default_finance_book')
|
||||||
|
|
||||||
for key, value in filters.items():
|
for key, value in filters.items():
|
||||||
if value:
|
if value:
|
||||||
gl_filters.update({
|
gl_filters.update({
|
||||||
key: value
|
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`
|
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
|
where company=%(company)s
|
||||||
{additional_conditions}
|
{additional_conditions}
|
||||||
and posting_date <= %(to_date)s
|
and posting_date <= %(to_date)s
|
||||||
order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) #nosec
|
order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) #nosec
|
||||||
|
|
||||||
if filters and filters.get('presentation_currency'):
|
if filters and filters.get('presentation_currency'):
|
||||||
convert_to_presentation_currency(gl_entries, get_currency(filters))
|
convert_to_presentation_currency(gl_entries, get_currency(filters))
|
||||||
|
|
||||||
for entry in gl_entries:
|
for entry in gl_entries:
|
||||||
gl_entries_by_account.setdefault(entry.account, []).append(entry)
|
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):
|
def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user