mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 06:29:20 +00:00
Merge pull request #17778 from deepeshgarg007/lead_owner
fix: Lead owner efficiency report query and column fixes
This commit is contained in:
@@ -11,7 +11,7 @@ def execute(filters=None):
|
|||||||
columns=get_columns("Campaign Name")
|
columns=get_columns("Campaign Name")
|
||||||
data=get_lead_data(filters or {}, "Campaign Name")
|
data=get_lead_data(filters or {}, "Campaign Name")
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
def get_columns(based_on):
|
def get_columns(based_on):
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -69,21 +69,21 @@ def get_columns(based_on):
|
|||||||
"width": 100
|
"width": 100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_lead_data(filters, based_on):
|
def get_lead_data(filters, based_on):
|
||||||
based_on_field = frappe.scrub(based_on)
|
based_on_field = frappe.scrub(based_on)
|
||||||
conditions = get_filter_conditions(filters)
|
conditions = get_filter_conditions(filters)
|
||||||
|
|
||||||
lead_details = frappe.db.sql("""
|
lead_details = frappe.db.sql("""
|
||||||
select {based_on_field}, name
|
select {based_on_field}, name
|
||||||
from `tabLead`
|
from `tabLead`
|
||||||
where {based_on_field} is not null and {based_on_field} != '' {conditions}
|
where {based_on_field} is not null and {based_on_field} != '' {conditions}
|
||||||
""".format(based_on_field=based_on_field, conditions=conditions), filters, as_dict=1)
|
""".format(based_on_field=based_on_field, conditions=conditions), filters, as_dict=1)
|
||||||
|
|
||||||
lead_map = frappe._dict()
|
lead_map = frappe._dict()
|
||||||
for d in lead_details:
|
for d in lead_details:
|
||||||
lead_map.setdefault(d.get(based_on_field), []).append(d.name)
|
lead_map.setdefault(d.get(based_on_field), []).append(d.name)
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for based_on_value, leads in lead_map.items():
|
for based_on_value, leads in lead_map.items():
|
||||||
row = {
|
row = {
|
||||||
@@ -94,42 +94,42 @@ def get_lead_data(filters, based_on):
|
|||||||
row["opp_count"] = get_lead_opp_count(leads)
|
row["opp_count"] = get_lead_opp_count(leads)
|
||||||
row["order_count"] = get_quotation_ordered_count(leads)
|
row["order_count"] = get_quotation_ordered_count(leads)
|
||||||
row["order_value"] = get_order_amount(leads) or 0
|
row["order_value"] = get_order_amount(leads) or 0
|
||||||
|
|
||||||
row["opp_lead"] = flt(row["opp_count"]) / flt(row["lead_count"] or 1.0) * 100.0
|
row["opp_lead"] = flt(row["opp_count"]) / flt(row["lead_count"] or 1.0) * 100.0
|
||||||
row["quot_lead"] = flt(row["quot_count"]) / flt(row["lead_count"] or 1.0) * 100.0
|
row["quot_lead"] = flt(row["quot_count"]) / flt(row["lead_count"] or 1.0) * 100.0
|
||||||
|
|
||||||
row["order_quot"] = flt(row["order_count"]) / flt(row["quot_count"] or 1.0) * 100.0
|
row["order_quot"] = flt(row["order_count"]) / flt(row["quot_count"] or 1.0) * 100.0
|
||||||
|
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_filter_conditions(filters):
|
def get_filter_conditions(filters):
|
||||||
conditions=""
|
conditions=""
|
||||||
if filters.from_date:
|
if filters.from_date:
|
||||||
conditions += " and date(creation) >= %(from_date)s"
|
conditions += " and date(creation) >= %(from_date)s"
|
||||||
if filters.to_date:
|
if filters.to_date:
|
||||||
conditions += " and date(creation) <= %(to_date)s"
|
conditions += " and date(creation) <= %(to_date)s"
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
def get_lead_quotation_count(leads):
|
def get_lead_quotation_count(leads):
|
||||||
return frappe.db.sql("""select count(name) from `tabQuotation`
|
return frappe.db.sql("""select count(name) from `tabQuotation`
|
||||||
where lead in (%s)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
where quotation_to = 'Lead' and party_name in (%s)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0] #nosec
|
||||||
|
|
||||||
def get_lead_opp_count(leads):
|
def get_lead_opp_count(leads):
|
||||||
return frappe.db.sql("""select count(name) from `tabOpportunity`
|
return frappe.db.sql("""select count(name) from `tabOpportunity`
|
||||||
where lead in (%s)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
where opportunity_from = 'Lead' and party_name in (%s)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
||||||
|
|
||||||
def get_quotation_ordered_count(leads):
|
def get_quotation_ordered_count(leads):
|
||||||
return frappe.db.sql("""select count(name)
|
return frappe.db.sql("""select count(name)
|
||||||
from `tabQuotation` where status = 'Ordered'
|
from `tabQuotation` where status = 'Ordered' and quotation_to = 'Lead'
|
||||||
and lead in (%s)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
and party_name in (%s)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
||||||
|
|
||||||
def get_order_amount(leads):
|
def get_order_amount(leads):
|
||||||
return frappe.db.sql("""select sum(base_net_amount)
|
return frappe.db.sql("""select sum(base_net_amount)
|
||||||
from `tabSales Order Item`
|
from `tabSales Order Item`
|
||||||
where prevdoc_docname in (
|
where prevdoc_docname in (
|
||||||
select name from `tabQuotation` where status = 'Ordered'
|
select name from `tabQuotation` where status = 'Ordered'
|
||||||
and lead in (%s)
|
and quotation_to = 'Lead' and party_name in (%s)
|
||||||
)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
)""" % ', '.join(["%s"]*len(leads)), tuple(leads))[0][0]
|
||||||
@@ -11,16 +11,61 @@ def execute(filters=None):
|
|||||||
columns=get_columns()
|
columns=get_columns()
|
||||||
data=get_lead_data(filters, "Lead Owner")
|
data=get_lead_data(filters, "Lead Owner")
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
return [
|
return [
|
||||||
_("Lead Owner") + ":Data:130",
|
{
|
||||||
_("Lead Count") + ":Int:80",
|
"fieldname": "lead_owner",
|
||||||
_("Opp Count") + ":Int:80",
|
"label": _("Lead Owner"),
|
||||||
_("Quot Count") + ":Int:80",
|
"fieldtype": "Data",
|
||||||
_("Order Count") + ":Int:100",
|
"width": "130"
|
||||||
_("Order Value") + ":Float:100",
|
},
|
||||||
_("Opp/Lead %") + ":Float:100",
|
{
|
||||||
_("Quot/Lead %") + ":Float:100",
|
"fieldname": "lead_count",
|
||||||
_("Order/Quot %") + ":Float:100"
|
"label": _("Lead Count"),
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"width": "80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "opp_count",
|
||||||
|
"label": _("Opp Count"),
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"width": "80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "quot_count",
|
||||||
|
"label": _("Quot Count"),
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"width": "80"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "order_count",
|
||||||
|
"label": _("Order Count"),
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"width": "100"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "order_value",
|
||||||
|
"label": _("Order Value"),
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"width": "100"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "opp_lead",
|
||||||
|
"label": _("Opp/Lead %"),
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"width": "100"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "quot_lead",
|
||||||
|
"label": _("Quot/Lead %"),
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"width": "100"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "order_quot",
|
||||||
|
"label": _("Order/Quot %"),
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"width": "100"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user