lost opportunity

This commit is contained in:
Anupam K 2020-08-23 17:15:40 +05:30
parent d01caac852
commit 64e84643fb
3 changed files with 84 additions and 24 deletions

View File

@ -140,18 +140,19 @@ def get_data(filters):
`tabAddress`.name=`tabDynamic Link`.parent)
WHERE
company = %(company)s
AND `tabLead`.creation BETWEEN %(from_date)s AND %(to_date)s
AND `tabLead`.creation BETWEEN %(from_date)s AND %(to_date)s
{conditions}
ORDER BY
`tabLead`.creation asc """.format(conditions=get_conditions(filters)), filters, as_dict=1)
def get_conditions(filters) :
conditions = ""
conditions = []
if filters.get("territory"):
conditions+=" and territory=%(territory)s "
conditions.append(" and `tabLead`.territory=%(territory)s")
if filters.get("status"):
conditions+=" and status=%(status)s "
conditions.append(" and `tabLead`.status=%(status)s")
return " ".join(conditions) if conditions else ""
return conditions

View File

@ -12,6 +12,32 @@ frappe.query_reports["Lost Opportunity"] = {
"default": frappe.defaults.get_user_default("Company"),
"reqd": 1
},
{
"fieldname":"from_date",
"label": __("From Date"),
"fieldtype": "Date",
"default": frappe.datetime.add_months(frappe.datetime.get_today(), -12),
"reqd": 1
},
{
"fieldname":"to_date",
"label": __("To Date"),
"fieldtype": "Date",
"default": frappe.datetime.get_today(),
"reqd": 1
},
{
"fieldname":"lost_reason",
"label": __("Lost Reason"),
"fieldtype": "Link",
"options": "Opportunity Lost Reason"
},
{
"fieldname":"territory",
"label": __("Territory"),
"fieldtype": "Link",
"options": "Territory"
},
{
"fieldname":"opportunity_from",
"label": __("Opportunity From"),

View File

@ -44,18 +44,32 @@ def get_columns():
"fieldtype": "Data",
"width": 130
},
{
"label": _("Next Contact By"),
"fieldname": "contact_by",
"fieldtype": "Link",
"options": "User",
"width": 120
},
{
"label": _("Lost Reasons"),
"fieldname": "lost_reason",
"fieldtype": "Data",
"width": 220
},
{
"label": _("Sales Stage"),
"fieldname": "sales_stage",
"fieldtype": "Link",
"options": "Sales Stage",
"width": 150
},
{
"label": _("Territory"),
"fieldname": "territory",
"fieldtype": "Link",
"options": "Territory",
"width": 150
},
{
"label": _("Next Contact By"),
"fieldname": "contact_by",
"fieldtype": "Link",
"options": "User",
"width": 150
}
]
return columns
@ -69,30 +83,49 @@ def get_data(filters):
`tabOpportunity`.customer_name,
`tabOpportunity`.opportunity_type,
`tabOpportunity`.contact_by,
GROUP_CONCAT(`tabLost Reason Detail`.lost_reason separator ', ') lost_reason
GROUP_CONCAT(`tabOpportunity Lost Reason Detail`.lost_reason separator ', ') lost_reason,
`tabOpportunity`.sales_stage,
`tabOpportunity`.territory
FROM
`tabOpportunity`
LEFT JOIN `tabLost Reason Detail`
ON `tabLost Reason Detail`.parenttype = 'Opportunity' and `tabLost Reason Detail`.parent = `tabOpportunity`.name
`tabOpportunity`
{join}
WHERE
`tabOpportunity`.status = 'Lost' and `tabOpportunity`.company = %(company)s
{conditions}
AND `tabOpportunity`.modified BETWEEN %(from_date)s AND %(to_date)s
{conditions}
GROUP BY
`tabOpportunity`.name
`tabOpportunity`.name
ORDER BY
`tabOpportunity`.creation asc """.format(conditions=get_conditions(filters)), filters, as_dict=1)
`tabOpportunity`.creation asc """.format(conditions=get_conditions(filters), join=get_join(filters)), filters, as_dict=1)
def get_conditions(filters) :
def get_conditions(filters):
conditions = []
if filters.get("territory"):
conditions.append(" and `tabOpportunity`.territory=%(territory)s")
if filters.get("opportunity_from"):
conditions.append("opportunity_from=%(opportunity_from)s")
conditions.append(" and `tabOpportunity`.opportunity_from=%(opportunity_from)s")
if filters.get("party_name"):
conditions.append("party_name=%(party_name)s")
conditions.append(" and `tabOpportunity`.party_name=%(party_name)s")
if filters.get("contact_by"):
conditions.append("contact_by=%(contact_by)s")
conditions.append(" and `tabOpportunity`.contact_by=%(contact_by)s")
return " and {}".format(" and ".join(conditions)) if conditions else ""
return " ".join(conditions) if conditions else ""
def get_join(filters):
join = """LEFT JOIN `tabOpportunity Lost Reason Detail`
ON `tabOpportunity Lost Reason Detail`.parenttype = 'Opportunity' and
`tabOpportunity Lost Reason Detail`.parent = `tabOpportunity`.name"""
if filters.get("lost_reason"):
join = """JOIN `tabOpportunity Lost Reason Detail`
ON `tabOpportunity Lost Reason Detail`.parenttype = 'Opportunity' and
`tabOpportunity Lost Reason Detail`.parent = `tabOpportunity`.name and
`tabOpportunity Lost Reason Detail`.lost_reason = '{0}'
""".format(filters.get("lost_reason"))
return join