fix: get ongoing deals and won deals based on closed_on date
(cherry picked from commit 81dc4e1138c86a5ab4a80ab57d1a521bc65ecc1b)
This commit is contained in:
parent
64dfa77022
commit
697ed4eb98
@ -87,14 +87,13 @@ def get_lead_count(from_date, to_date, user="", conds="", return_result=False):
|
|||||||
"value": current_month_leads,
|
"value": current_month_leads,
|
||||||
"delta": delta_in_percentage,
|
"delta": delta_in_percentage,
|
||||||
"deltaSuffix": "%",
|
"deltaSuffix": "%",
|
||||||
"negativeIsBetter": False,
|
|
||||||
"tooltip": _("Total number of leads"),
|
"tooltip": _("Total number of leads"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_deal_count(from_date, to_date, user="", conds="", return_result=False):
|
def get_deal_count(from_date, to_date, user="", conds="", return_result=False):
|
||||||
"""
|
"""
|
||||||
Get deal count for the dashboard.
|
Get ongoing deal count for the dashboard.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
diff = frappe.utils.date_diff(to_date, from_date)
|
diff = frappe.utils.date_diff(to_date, from_date)
|
||||||
@ -102,25 +101,28 @@ def get_deal_count(from_date, to_date, user="", conds="", return_result=False):
|
|||||||
diff = 1
|
diff = 1
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
conds += f" AND deal_owner = '{user}'"
|
conds += f" AND d.deal_owner = '{user}'"
|
||||||
|
|
||||||
result = frappe.db.sql(
|
result = frappe.db.sql(
|
||||||
f"""
|
f"""
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(CASE
|
COUNT(CASE
|
||||||
WHEN creation >= %(from_date)s AND creation < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
WHEN d.creation >= %(from_date)s AND d.creation < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
||||||
{conds}
|
AND s.type NOT IN ('Won', 'Lost')
|
||||||
THEN name
|
{conds}
|
||||||
ELSE NULL
|
THEN d.name
|
||||||
END) as current_month_deals,
|
ELSE NULL
|
||||||
|
END) as current_month_deals,
|
||||||
|
|
||||||
COUNT(CASE
|
COUNT(CASE
|
||||||
WHEN creation >= %(prev_from_date)s AND creation < %(from_date)s
|
WHEN d.creation >= %(prev_from_date)s AND d.creation < %(from_date)s
|
||||||
{conds}
|
AND s.type NOT IN ('Won', 'Lost')
|
||||||
THEN name
|
{conds}
|
||||||
ELSE NULL
|
THEN d.name
|
||||||
END) as prev_month_deals
|
ELSE NULL
|
||||||
FROM `tabCRM Deal`
|
END) as prev_month_deals
|
||||||
|
FROM `tabCRM Deal` d
|
||||||
|
JOIN `tabCRM Deal Status` s ON d.status = s.name
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"from_date": from_date,
|
"from_date": from_date,
|
||||||
@ -141,12 +143,11 @@ def get_deal_count(from_date, to_date, user="", conds="", return_result=False):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": _("Total Deals"),
|
"title": _("Ongoing Deals"),
|
||||||
"value": current_month_deals,
|
"value": current_month_deals,
|
||||||
"delta": delta_in_percentage,
|
"delta": delta_in_percentage,
|
||||||
"deltaSuffix": "%",
|
"deltaSuffix": "%",
|
||||||
"negativeIsBetter": False,
|
"tooltip": _("Total number of ongoing deals"),
|
||||||
"tooltip": _("Total number of deals"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -166,7 +167,7 @@ def get_won_deal_count(from_date, to_date, user="", conds="", return_result=Fals
|
|||||||
f"""
|
f"""
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(CASE
|
COUNT(CASE
|
||||||
WHEN d.creation >= %(from_date)s AND d.creation < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
WHEN d.closed_on >= %(from_date)s AND d.closed_on < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
||||||
AND s.type = 'Won'
|
AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
THEN d.name
|
THEN d.name
|
||||||
@ -174,7 +175,7 @@ def get_won_deal_count(from_date, to_date, user="", conds="", return_result=Fals
|
|||||||
END) as current_month_deals,
|
END) as current_month_deals,
|
||||||
|
|
||||||
COUNT(CASE
|
COUNT(CASE
|
||||||
WHEN d.creation >= %(prev_from_date)s AND d.creation < %(from_date)s
|
WHEN d.closed_on >= %(prev_from_date)s AND d.closed_on < %(from_date)s
|
||||||
AND s.type = 'Won'
|
AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
THEN d.name
|
THEN d.name
|
||||||
@ -206,7 +207,6 @@ def get_won_deal_count(from_date, to_date, user="", conds="", return_result=Fals
|
|||||||
"value": current_month_deals,
|
"value": current_month_deals,
|
||||||
"delta": delta_in_percentage,
|
"delta": delta_in_percentage,
|
||||||
"deltaSuffix": "%",
|
"deltaSuffix": "%",
|
||||||
"negativeIsBetter": False,
|
|
||||||
"tooltip": _("Total number of won deals"),
|
"tooltip": _("Total number of won deals"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user