Revert "[optimize] remove count(*) from queries"
diff --git a/erpnext/controllers/tests/test_recurring_document.py b/erpnext/controllers/tests/test_recurring_document.py
index 58558c4..d47c5c7 100644
--- a/erpnext/controllers/tests/test_recurring_document.py
+++ b/erpnext/controllers/tests/test_recurring_document.py
@@ -110,7 +110,7 @@
no_of_months = ({"Monthly": 1, "Quarterly": 3, "Yearly": 12})[base_doc.recurring_type]
def _test(i):
- obj.assertEquals(i+1, frappe.db.sql("""select count(name) from `tab%s`
+ obj.assertEquals(i+1, frappe.db.sql("""select count(*) from `tab%s`
where recurring_id=%s and (docstatus=1 or docstatus=0)""" % (base_doc.doctype, '%s'),
(base_doc.recurring_id))[0][0])
diff --git a/erpnext/patches/v4_0/fix_employee_user_id.py b/erpnext/patches/v4_0/fix_employee_user_id.py
index 2a8f76b..6f449f9 100644
--- a/erpnext/patches/v4_0/fix_employee_user_id.py
+++ b/erpnext/patches/v4_0/fix_employee_user_id.py
@@ -18,6 +18,6 @@
frappe.db.sql("""update `tabEmployee` set user_id=null
where user_id=%s and name!=%s""", (user_id, employee))
else:
- count = frappe.db.sql("""select count(name) from `tabEmployee` where user_id=%s""", user_id)[0][0]
+ count = frappe.db.sql("""select count(*) from `tabEmployee` where user_id=%s""", user_id)[0][0]
frappe.db.sql("""update `tabEmployee` set user_id=null
where user_id=%s limit %s""", (user_id, count - 1))
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py
index 71dc8bd..4d12efd 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.py
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.py
@@ -8,7 +8,7 @@
@frappe.whitelist()
def get_funnel_data(from_date, to_date):
- active_leads = frappe.db.sql("""select count(name) from `tabLead`
+ active_leads = frappe.db.sql("""select count(*) from `tabLead`
where (date(`modified`) between %s and %s)
and status != "Do Not Contact" """, (from_date, to_date))[0][0]
@@ -16,15 +16,15 @@
where (date(`modified`) between %s and %s)
and status != "Passive" """, (from_date, to_date))[0][0]
- opportunities = frappe.db.sql("""select count(name) from `tabOpportunity`
+ opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
where (date(`creation`) between %s and %s)
and status != "Lost" """, (from_date, to_date))[0][0]
- quotations = frappe.db.sql("""select count(name) from `tabQuotation`
+ quotations = frappe.db.sql("""select count(*) from `tabQuotation`
where docstatus = 1 and (date(`creation`) between %s and %s)
and status != "Lost" """, (from_date, to_date))[0][0]
- sales_orders = frappe.db.sql("""select count(name) from `tabSales Order`
+ sales_orders = frappe.db.sql("""select count(*) from `tabSales Order`
where docstatus = 1 and (date(`creation`) between %s and %s)""", (from_date, to_date))[0][0]
return [
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index 791e54e..ac999ed 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -177,7 +177,7 @@
if not user_id:
user_id = frappe.session.user
- return frappe.db.sql("""select count(name) from `tabToDo`
+ return frappe.db.sql("""select count(*) from `tabToDo`
where status='Open' and (owner=%s or assigned_by=%s)""",
(user_id, user_id))[0][0]
@@ -202,7 +202,7 @@
def get_issue_count(self):
"""Get count of Issue"""
- return frappe.db.sql("""select count(name) from `tabIssue`
+ return frappe.db.sql("""select count(*) from `tabIssue`
where status in ('Open','Replied') """)[0][0]
def get_project_list(self, user_id=None):
@@ -221,7 +221,7 @@
def get_project_count(self):
"""Get count of Project"""
- return frappe.db.sql("""select count(name) from `tabProject`
+ return frappe.db.sql("""select count(*) from `tabProject`
where status='Open' and project_type='External'""")[0][0]
def set_accounting_cards(self, context):
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index e638161..12899cd 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -127,7 +127,7 @@
def get_group_item_count(item_group):
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(item_group)])
- return frappe.db.sql("""select count(name) from `tabItem`
+ return frappe.db.sql("""select count(*) from `tabItem`
where docstatus = 0 and show_in_website = 1
and (item_group in (%s)
or name in (select parent from `tabWebsite Item Group`
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index 9b16ad7..97ef329 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -23,7 +23,7 @@
"Notification Control")
# if no company, show a dialog box to create a new company
- bootinfo.customer_count = frappe.db.sql("""select count(name) from tabCustomer""")[0][0]
+ bootinfo.customer_count = frappe.db.sql("""select count(*) from tabCustomer""")[0][0]
if not bootinfo.customer_count:
bootinfo.setup_complete = frappe.db.sql("""select name from