1
0
forked from test/crm

fix: used expected closed date & deal value for forecasting

(cherry picked from commit 7fc26a5202b89476ec5e277601243cf8299ed10f)
This commit is contained in:
Shariq Ansari 2025-07-13 12:03:17 +05:30 committed by Mergify
parent a6c60ffecb
commit 209da0f84e
4 changed files with 14 additions and 13 deletions

View File

@ -615,23 +615,24 @@ def get_forecasted_revenue(user="", deal_conds=""):
result = frappe.db.sql(
f"""
SELECT
DATE_FORMAT(d.close_date, '%Y-%m') AS month,
DATE_FORMAT(d.expected_closure_date, '%Y-%m') AS month,
SUM(
CASE
WHEN d.status = 'Lost' THEN d.deal_value * IFNULL(d.exchange_rate, 1)
ELSE d.deal_value * IFNULL(d.probability, 0) / 100 * IFNULL(d.exchange_rate, 1) -- forecasted
WHEN s.type = 'Lost' THEN d.expected_deal_value * IFNULL(d.exchange_rate, 1)
ELSE d.expected_deal_value * IFNULL(d.probability, 0) / 100 * IFNULL(d.exchange_rate, 1) -- forecasted
END
) AS forecasted,
SUM(
CASE
WHEN d.status = 'Won' THEN d.deal_value * IFNULL(d.exchange_rate, 1) -- actual
WHEN s.type = 'Won' THEN d.deal_value * IFNULL(d.exchange_rate, 1) -- actual
ELSE 0
END
) AS actual
FROM `tabCRM Deal` AS d
WHERE d.close_date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
JOIN `tabCRM Deal Status` s ON d.status = s.name
WHERE d.expected_closure_date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
{deal_conds}
GROUP BY DATE_FORMAT(d.close_date, '%Y-%m')
GROUP BY DATE_FORMAT(d.expected_closure_date, '%Y-%m')
ORDER BY month
""",
as_dict=True,

View File

@ -160,7 +160,7 @@ def add_forecasting_section(layout, doctype):
"columns": [
{
"name": "column_" + str(random_string(4)),
"fields": ["close_date", "probability", "deal_value"],
"fields": ["expected_closure_date", "probability", "expected_deal_value"],
}
],
},

View File

@ -61,7 +61,7 @@
},
{
"default": "0",
"description": "It will make deal's \"Close Date\" & \"Deal Value\" mandatory to get accurate forecasting insights",
"description": "It will make deal's \"Expected Closure Date\" & \"Expected Deal Value\" mandatory to get accurate forecasting insights",
"fieldname": "enable_forecasting",
"fieldtype": "Check",
"label": "Enable Forecasting"
@ -77,7 +77,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2025-07-10 16:35:25.030011",
"modified": "2025-07-13 11:58:34.857638",
"modified_by": "Administrator",
"module": "FCRM",
"name": "FCRM Settings",

View File

@ -38,24 +38,24 @@ class FCRMSettings(Document):
delete_property_setter(
"CRM Deal",
"reqd",
"close_date",
"expected_closure_date",
)
delete_property_setter(
"CRM Deal",
"reqd",
"deal_value",
"expected_deal_value",
)
else:
make_property_setter(
"CRM Deal",
"close_date",
"expected_closure_date",
"reqd",
1 if self.enable_forecasting else 0,
"Check",
)
make_property_setter(
"CRM Deal",
"deal_value",
"expected_deal_value",
"reqd",
1 if self.enable_forecasting else 0,
"Check",