feat: add method for ordered quantity in supplier scorecard (#35930)
fix: add method for getting ordered quantity in the supplier scorecard variable.
Co-authored-by: vishnu <vishnuviswambara2002@gmail.com>
diff --git a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py
index 486bf23..58da851 100644
--- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py
+++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py
@@ -329,6 +329,11 @@
"variable_label": "Total Shipments",
"path": "get_total_shipments",
},
+ {
+ "param_name": "total_ordered",
+ "variable_label": "Total Ordered",
+ "path": "get_ordered_qty",
+ },
]
install_standing_docs = [
{
diff --git a/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.py b/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.py
index fb8819e..4080d1f 100644
--- a/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.py
+++ b/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.py
@@ -7,6 +7,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
+from frappe.query_builder.functions import Sum
from frappe.utils import getdate
@@ -422,6 +423,23 @@
return data
+def get_ordered_qty(scorecard):
+ """Returns the total number of ordered quantity (based on Purchase Orders)"""
+
+ po = frappe.qb.DocType("Purchase Order")
+
+ return (
+ frappe.qb.from_(po)
+ .select(Sum(po.total_qty))
+ .where(
+ (po.supplier == scorecard.supplier)
+ & (po.docstatus == 1)
+ & (po.transaction_date >= scorecard.get("start_date"))
+ & (po.transaction_date <= scorecard.get("end_date"))
+ )
+ ).run(as_list=True)[0][0] or 0
+
+
def get_rfq_total_number(scorecard):
"""Gets the total number of RFQs sent to supplier"""
supplier = frappe.get_doc("Supplier", scorecard.supplier)