Skip to content

Instantly share code, notes, and snippets.

@itsyosefali
Last active January 8, 2023 11:58
Show Gist options
  • Select an option

  • Save itsyosefali/a47cccac446f95dffdfbf0a3cc275cf3 to your computer and use it in GitHub Desktop.

Select an option

Save itsyosefali/a47cccac446f95dffdfbf0a3cc275cf3 to your computer and use it in GitHub Desktop.
تقرير حركة الخزينة
sql_account_filter = ""
if filters.get("account"):
escaped_input = frappe.db.escape(filters.get("account"))
sql_account_filter = f"AND `tabGL Entry`.account = {escaped_input}"
sql_date_cond = ""
if filters.get("date_from") and filters.get("date_to"):
date_from = frappe.db.escape(filters.get("date_from"))
date_to = frappe.db.escape(filters.get("date_to"))
sql_date_cond = f"""and posting_date between {date_from} and {date_to} """
elif filters.get("date_from"):
date_from = frappe.db.escape(filters.get("date_from"))
sql_date_cond = f"""and posting_date >= {date_from}"""
elif filters.get("date_to"):
date_to = frappe.db.escape(filters.get("date_to"))
sql_date_cond = f"""and posting_date <= {date_to} """
res = frappe.db.sql(f"""SELECT
`tabGL Entry`.posting_date,
`tabGL Entry`.account,
`tabGL Entry`.debit,
`tabGL Entry`.credit,
`tabGL Entry`.voucher_no
FROM `tabGL Entry`
where
1=1
{sql_date_cond}
{sql_account_filter}
""", as_dict=True)
for item in res:
div_res = item.debit + item.credit
item.s = div_res
result = res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment