mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-31 23:07:51 +00:00
fix(buying): show linked record count on Supplier Scorecard connections (backport #59079)
Supplier Scorecard connections show the linked record count.
(cherry picked from commit 9be19e69b5)
This commit is contained in:
@@ -186,11 +186,9 @@ class SupplierScorecard(Document):
|
||||
return above_min and (not standing.max_grade or standing.max_grade > score)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_timeline_data(doctype, name):
|
||||
def get_timeline_data(doctype: str, name: str) -> dict[float, float]:
|
||||
# Get a list of all the associated scorecards
|
||||
scs = frappe.get_doc(doctype, name)
|
||||
out = {}
|
||||
timeline_data = {}
|
||||
scorecards = frappe.db.sql(
|
||||
"""
|
||||
@@ -212,8 +210,7 @@ def get_timeline_data(doctype, name):
|
||||
for single_date in daterange(start_date, end_date):
|
||||
timeline_data[time.mktime(single_date.timetuple())] = total_score
|
||||
|
||||
out["timeline_data"] = timeline_data
|
||||
return out
|
||||
return timeline_data
|
||||
|
||||
|
||||
def daterange(start_date, end_date):
|
||||
|
||||
@@ -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"]}],
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import (
|
||||
from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import (
|
||||
make_supplier_scorecard as make_scorecard_period,
|
||||
)
|
||||
from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard_dashboard import get_data
|
||||
from erpnext.setup.doctype.employee.test_employee import make_employee
|
||||
|
||||
|
||||
@@ -199,6 +200,30 @@ class TestSupplierScorecard(FrappeTestCase):
|
||||
doc.update_standing()
|
||||
self.assertEqual(doc.status, "Excellent")
|
||||
|
||||
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])
|
||||
|
||||
Reference in New Issue
Block a user