fix: used closed_date instead of closed_on and set closed_date if status type is Won
(cherry picked from commit f82019e510612bd9803f9947240d155479d5d665)
This commit is contained in:
parent
209da0f84e
commit
107eeae116
@ -202,7 +202,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.closed_on >= %(from_date)s AND d.closed_on < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
WHEN d.closed_date >= %(from_date)s AND d.closed_date < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
||||||
AND s.type = 'Won'
|
AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
THEN d.name
|
THEN d.name
|
||||||
@ -210,7 +210,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.closed_on >= %(prev_from_date)s AND d.closed_on < %(from_date)s
|
WHEN d.closed_date >= %(prev_from_date)s AND d.closed_date < %(from_date)s
|
||||||
AND s.type = 'Won'
|
AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
THEN d.name
|
THEN d.name
|
||||||
@ -218,7 +218,7 @@ def get_won_deal_count(from_date, to_date, user="", conds="", return_result=Fals
|
|||||||
END) as prev_month_deals,
|
END) as prev_month_deals,
|
||||||
|
|
||||||
AVG(CASE
|
AVG(CASE
|
||||||
WHEN d.closed_on >= %(from_date)s AND d.closed_on < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
WHEN d.closed_date >= %(from_date)s AND d.closed_date < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
||||||
AND s.type = 'Won'
|
AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
THEN d.deal_value * IFNULL(d.exchange_rate, 1)
|
THEN d.deal_value * IFNULL(d.exchange_rate, 1)
|
||||||
@ -226,7 +226,7 @@ def get_won_deal_count(from_date, to_date, user="", conds="", return_result=Fals
|
|||||||
END) as current_month_avg_value,
|
END) as current_month_avg_value,
|
||||||
|
|
||||||
AVG(CASE
|
AVG(CASE
|
||||||
WHEN d.closed_on >= %(prev_from_date)s AND d.closed_on < %(from_date)s
|
WHEN d.closed_date >= %(prev_from_date)s AND d.closed_date < %(from_date)s
|
||||||
AND s.type = 'Won'
|
AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
THEN d.deal_value * IFNULL(d.exchange_rate, 1)
|
THEN d.deal_value * IFNULL(d.exchange_rate, 1)
|
||||||
@ -353,18 +353,18 @@ def get_average_time_to_close(from_date, to_date, user="", conds="", return_resu
|
|||||||
result = frappe.db.sql(
|
result = frappe.db.sql(
|
||||||
f"""
|
f"""
|
||||||
SELECT
|
SELECT
|
||||||
AVG(CASE WHEN d.closed_on >= %(from_date)s AND d.closed_on < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
AVG(CASE WHEN d.closed_date >= %(from_date)s AND d.closed_date < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
||||||
THEN TIMESTAMPDIFF(DAY, COALESCE(l.creation, d.creation), d.closed_on) END) as current_avg_lead,
|
THEN TIMESTAMPDIFF(DAY, COALESCE(l.creation, d.creation), d.closed_date) END) as current_avg_lead,
|
||||||
AVG(CASE WHEN d.closed_on >= %(prev_from_date)s AND d.closed_on < %(prev_to_date)s
|
AVG(CASE WHEN d.closed_date >= %(prev_from_date)s AND d.closed_date < %(prev_to_date)s
|
||||||
THEN TIMESTAMPDIFF(DAY, COALESCE(l.creation, d.creation), d.closed_on) END) as prev_avg_lead,
|
THEN TIMESTAMPDIFF(DAY, COALESCE(l.creation, d.creation), d.closed_date) END) as prev_avg_lead,
|
||||||
AVG(CASE WHEN d.closed_on >= %(from_date)s AND d.closed_on < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
AVG(CASE WHEN d.closed_date >= %(from_date)s AND d.closed_date < DATE_ADD(%(to_date)s, INTERVAL 1 DAY)
|
||||||
THEN TIMESTAMPDIFF(DAY, d.creation, d.closed_on) END) as current_avg_deal,
|
THEN TIMESTAMPDIFF(DAY, d.creation, d.closed_date) END) as current_avg_deal,
|
||||||
AVG(CASE WHEN d.closed_on >= %(prev_from_date)s AND d.closed_on < %(prev_to_date)s
|
AVG(CASE WHEN d.closed_date >= %(prev_from_date)s AND d.closed_date < %(prev_to_date)s
|
||||||
THEN TIMESTAMPDIFF(DAY, d.creation, d.closed_on) END) as prev_avg_deal
|
THEN TIMESTAMPDIFF(DAY, d.creation, d.closed_date) END) as prev_avg_deal
|
||||||
FROM `tabCRM Deal` AS d
|
FROM `tabCRM Deal` AS d
|
||||||
JOIN `tabCRM Deal Status` s ON d.status = s.name
|
JOIN `tabCRM Deal Status` s ON d.status = s.name
|
||||||
LEFT JOIN `tabCRM Lead` l ON d.lead = l.name
|
LEFT JOIN `tabCRM Lead` l ON d.lead = l.name
|
||||||
WHERE d.closed_on IS NOT NULL AND s.type = 'Won'
|
WHERE d.closed_date IS NOT NULL AND s.type = 'Won'
|
||||||
{conds}
|
{conds}
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
|
|||||||
@ -25,8 +25,8 @@ class CRMDeal(Document):
|
|||||||
self.assign_agent(self.deal_owner)
|
self.assign_agent(self.deal_owner)
|
||||||
if self.has_value_changed("status"):
|
if self.has_value_changed("status"):
|
||||||
add_status_change_log(self)
|
add_status_change_log(self)
|
||||||
if self.status == "Won":
|
if frappe.db.get_value("CRM Deal Status", self.status, "type") == "Won":
|
||||||
self.closed_on = frappe.utils.now_datetime()
|
self.closed_date = frappe.utils.nowdate()
|
||||||
self.validate_forcasting_fields()
|
self.validate_forcasting_fields()
|
||||||
self.validate_lost_reason()
|
self.validate_lost_reason()
|
||||||
self.update_exchange_rate()
|
self.update_exchange_rate()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user