Merge pull request #42625 from frappe/mergify/bp/version-14-hotfix/pr-42555
refactor: date filters should be mandatory in Sales Pipeline Analytics report (backport #42555)
This commit is contained in:
@@ -8,7 +8,7 @@ from itertools import groupby
|
|||||||
import frappe
|
import frappe
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint, flt
|
from frappe.utils import cint, flt, getdate
|
||||||
|
|
||||||
from erpnext.setup.utils import get_exchange_rate
|
from erpnext.setup.utils import get_exchange_rate
|
||||||
|
|
||||||
@@ -21,7 +21,15 @@ class SalesPipelineAnalytics:
|
|||||||
def __init__(self, filters=None):
|
def __init__(self, filters=None):
|
||||||
self.filters = frappe._dict(filters or {})
|
self.filters = frappe._dict(filters or {})
|
||||||
|
|
||||||
|
def validate_filters(self):
|
||||||
|
if not self.filters.from_date:
|
||||||
|
frappe.throw(_("From Date is mandatory"))
|
||||||
|
|
||||||
|
if not self.filters.to_date:
|
||||||
|
frappe.throw(_("To Date is mandatory"))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.validate_filters()
|
||||||
self.get_columns()
|
self.get_columns()
|
||||||
self.get_data()
|
self.get_data()
|
||||||
self.get_chart_data()
|
self.get_chart_data()
|
||||||
@@ -185,7 +193,7 @@ class SalesPipelineAnalytics:
|
|||||||
count_or_amount = info.get(based_on)
|
count_or_amount = info.get(based_on)
|
||||||
|
|
||||||
if self.filters.get("pipeline_by") == "Owner":
|
if self.filters.get("pipeline_by") == "Owner":
|
||||||
if value == "Not Assigned" or value == "[]" or value is None:
|
if value == "Not Assigned" or value == "[]" or value is None or not value:
|
||||||
assigned_to = ["Not Assigned"]
|
assigned_to = ["Not Assigned"]
|
||||||
else:
|
else:
|
||||||
assigned_to = json.loads(value)
|
assigned_to = json.loads(value)
|
||||||
@@ -227,10 +235,9 @@ class SalesPipelineAnalytics:
|
|||||||
|
|
||||||
def get_month_list(self):
|
def get_month_list(self):
|
||||||
month_list = []
|
month_list = []
|
||||||
current_date = date.today()
|
current_date = getdate(self.filters.get("from_date"))
|
||||||
month_number = date.today().month
|
|
||||||
|
|
||||||
for _month in range(month_number, 13):
|
while current_date < getdate(self.filters.get("to_date")):
|
||||||
month_list.append(current_date.strftime("%B"))
|
month_list.append(current_date.strftime("%B"))
|
||||||
current_date = current_date + relativedelta(months=1)
|
current_date = current_date + relativedelta(months=1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.tests.utils import FrappeTestCase
|
||||||
|
|
||||||
from erpnext.crm.report.sales_pipeline_analytics.sales_pipeline_analytics import execute
|
from erpnext.crm.report.sales_pipeline_analytics.sales_pipeline_analytics import execute
|
||||||
|
|
||||||
|
|
||||||
class TestSalesPipelineAnalytics(unittest.TestCase):
|
class TestSalesPipelineAnalytics(FrappeTestCase):
|
||||||
@classmethod
|
def setUp(self):
|
||||||
def setUpClass(self):
|
|
||||||
frappe.db.delete("Opportunity")
|
frappe.db.delete("Opportunity")
|
||||||
create_company()
|
create_company()
|
||||||
create_customer()
|
create_customer()
|
||||||
create_opportunity()
|
create_opportunity()
|
||||||
|
|
||||||
def test_sales_pipeline_analytics(self):
|
def test_sales_pipeline_analytics(self):
|
||||||
|
self.from_date = "2021-01-01"
|
||||||
|
self.to_date = "2021-12-31"
|
||||||
self.check_for_monthly_and_number()
|
self.check_for_monthly_and_number()
|
||||||
self.check_for_monthly_and_amount()
|
self.check_for_monthly_and_amount()
|
||||||
self.check_for_quarterly_and_number()
|
self.check_for_quarterly_and_number()
|
||||||
@@ -28,6 +30,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -43,6 +47,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -59,6 +65,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -74,6 +82,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -90,6 +100,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -105,6 +117,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -121,6 +135,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -136,6 +152,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"status": "Open",
|
"status": "Open",
|
||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
|
"from_date": self.from_date,
|
||||||
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
@@ -153,8 +171,8 @@ class TestSalesPipelineAnalytics(unittest.TestCase):
|
|||||||
"opportunity_type": "Sales",
|
"opportunity_type": "Sales",
|
||||||
"company": "Best Test",
|
"company": "Best Test",
|
||||||
"opportunity_source": "Cold Calling",
|
"opportunity_source": "Cold Calling",
|
||||||
"from_date": "2021-08-01",
|
"from_date": self.from_date,
|
||||||
"to_date": "2021-08-31",
|
"to_date": self.to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
|
|||||||
Reference in New Issue
Block a user