Skip to content

Instantly share code, notes, and snippets.

@itsyosefali
Last active January 10, 2023 12:59
Show Gist options
  • Select an option

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

Select an option

Save itsyosefali/1df382d852be6e218c6481e6cb97bd5c to your computer and use it in GitHub Desktop.
الديون
party=""
if filters.get("party"):
escaped_input = frappe.db.escape(filters.get("party"))
party = f" AND `tabGL Entry`.party = {escaped_input}"
default_sales_partner=""
if filters.get("default_sales_partner"):
escaped_input = frappe.db.escape(filters.get("default_sales_partner"))
default_sales_partner = f" AND `tabCustomer`.default_sales_partner = {escaped_input}"
res = frappe.db.sql(f"""SELECT
`tabGL Entry`.party,
`tabGL Entry`.account,
`tabGL Entry`.debit,
`tabGL Entry`.credit,
`tabCustomer`.default_sales_partner
FROM `tabGL Entry`
INNER JOIN `tabCustomer`
on `tabCustomer`.name = `tabGL Entry`.party
where
`tabGL Entry`.party_type = 'Customer'
AND
`tabGL Entry`.is_cancelled = 0
{party}
{default_sales_partner}
group by
`tabGL Entry`.party
""", as_dict=True)
for item in res:
div_res = item.debit + (-item.credit)
item.s = div_res
item.s = item.s + (-item.s)
result = res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment