from future import unicode_literals
import frappe
from frappe.model.document import Document
query= frappe.db.sql(“”“select state, count() from Lead where state is not null group by state"“”)
frappe.get_all(“Lead”, fields = [“state”, "count()”]) for row in frappe.get_all(“Lead”, fields = [“state”, “count()"]):
print row[“state”]
print row["count()”]
Its not working. Can anyone tell what’s wrong in that ??
from future import unicode_literals
import frappe
from frappe.model.document import Document
import json
@frappe.whitelist()
def state_wise(state):
query= frappe.db.sql(“”“select state, count(lead_name) from tabLead where state is not null group by state”“”)
frappe.get_all(“Lead”, fields = [“state”, “count(lead_name)”])
print row[“state”]
print row[“count(*)”]
yes, when i was using only frappe.db.sql still it wan’t giving values
query= frappe.db.sql(“”“select state, count(lead_name) from tabLead where state is not null group by state”“”)
for row in query():
statelist=list(row)
state=statelist[0]
lead=statelist[1]
print “query = {}”.format(frappe.as_json(query))
return (state,lead)
query= frappe.db.sql(“”“select state, count(lead_name) from tabLead where state is not null group by state”“”)
for row in query:
state=row[0]
lead=row[1]
return (state,lead)
I think you are passing query instead of method in your frappe.call
Also, refer following code for clarity
from future import unicode_literals
import frappe
from frappe.model.document import Document
import json
@frappe.whitelist()
def state_wise(state):
state_wise_date = frappe.db.sql(""“select state, count(lead_name) as total_lead from `tabLead` where state is not null group by state”"")
return state_wise_data