fix(buying): show linked record count on Supplier Scorecard connections (#59079)

This commit is contained in:
Mihir Kandoi
2026-09-15 19:28:42 +05:30
committed by GitHub
parent 41ad83dfb1
commit 9be19e69b5
3 changed files with 27 additions and 8 deletions

View File

@@ -146,11 +146,7 @@ class SupplierScorecard(Document):
frappe.db.set_value("Supplier", self.supplier, fieldname, self.get(fieldname))
@frappe.whitelist()
def get_timeline_data(doctype: str, name: str):
# Get a list of all the associated scorecards
out = {}
def get_timeline_data(doctype: str, name: str) -> dict[float, float]:
timeline_data = {}
scorecards = frappe.get_all(
@@ -164,8 +160,7 @@ def get_timeline_data(doctype: str, name: str):
for single_date in daterange(sc.start_date, sc.end_date):
timeline_data[time.mktime(single_date.timetuple())] = sc.total_score
out["timeline_data"] = timeline_data
return out
return timeline_data
def daterange(start_date, end_date):

View File

@@ -6,6 +6,5 @@ def get_data():
"heatmap": True,
"heatmap_message": _("This covers all scorecards tied to this Setup"),
"fieldname": "supplier",
"method": "erpnext.buying.doctype.supplier_scorecard.supplier_scorecard.get_timeline_data",
"transactions": [{"label": _("Scorecards"), "items": ["Supplier Scorecard Period"]}],
}

View File

@@ -9,6 +9,7 @@ from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import (
get_scorecard_date,
make_all_scorecards,
)
from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard_dashboard import get_data
from erpnext.tests.utils import ERPNextTestSuite
@@ -89,6 +90,30 @@ class TestSupplierScorecard(ERPNextTestSuite):
self.assertGreater(created, 0)
self.assertEqual(make_all_scorecards(doc.name), 0)
def test_dashboard_endpoint_returns_connection_count_and_heatmap(self):
supplier = create_test_supplier("_Test Supplier SC Dashboard")
frappe.db.set_value("Supplier", supplier, "creation", add_days(nowdate(), -75))
frappe.delete_doc_if_exists("Supplier Scorecard", supplier)
doc = make_supplier_scorecard()
doc.supplier = supplier
doc.name = supplier
doc.insert()
endpoint = get_data().get("method") or "frappe.desk.notifications.get_open_count"
dashboard = frappe.get_attr(endpoint)("Supplier Scorecard", doc.name)
counts = {link["doctype"]: link["count"] for link in dashboard["count"]["external_links_found"]}
periods = frappe.db.count("Supplier Scorecard Period", {"supplier": supplier})
self.assertGreater(periods, 0)
self.assertEqual(counts["Supplier Scorecard Period"], periods)
timeline_data = dashboard["timeline_data"]
self.assertTrue(timeline_data)
for timestamp, score in timeline_data.items():
self.assertIsInstance(timestamp, int | float)
self.assertIsInstance(score, int | float)
def make_supplier_scorecard():
my_doc = frappe.get_doc(valid_scorecard[0])