Can we write query in jinja?

Hi everyone

Can we have something like this?

{% set total_unpaid=frappe.db.sql("""
        select sum(debit_in_account_currency) - sum(credit_in_account_currency)
        from `tabGL Entry`
        where party_type = 'Customer' and party= 'Shree Ganesh Ji'""") %}

Tried but no luck.

Showing below error.

UndefinedError: 'dict object' has no attribute 'sql'

You cannot write query but use frappe methods like frappe.get_list etc. based on your requirement.

@Pawan

Can I get unpaid amount in one variable in print format ?

Is there a specific predefined methods for this?

This unpaid amount is available in customer doctype dashboard

Any examples that I can look into?

Why do you need to make it in Jinja? It is frustrating. If you are using Web Forms on www folder, create another .py file with the same name as html. Code there and pass the values in Jinja Templates.

Source: https://frappe.io/docs/user/en/guides/portal-development/context

no brother you just write a function in .py file and attach it in jenv hooks and call this function in print format