diff --git a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py index 6e22acf01a..683a12ac95 100644 --- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py +++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py @@ -334,6 +334,11 @@ def make_default_records(): "variable_label": "Total Ordered", "path": "get_ordered_qty", }, + { + "param_name": "total_invoiced", + "variable_label": "Total Invoiced", + "path": "get_invoiced_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 4080d1fde0..6c91a049db 100644 --- a/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.py +++ b/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.py @@ -440,6 +440,23 @@ def get_ordered_qty(scorecard): ).run(as_list=True)[0][0] or 0 +def get_invoiced_qty(scorecard): + """Returns the total number of invoiced quantity (based on Purchase Invoice)""" + + pi = frappe.qb.DocType("Purchase Invoice") + + return ( + frappe.qb.from_(pi) + .select(Sum(pi.total_qty)) + .where( + (pi.supplier == scorecard.supplier) + & (pi.docstatus == 1) + & (pi.posting_date >= scorecard.get("start_date")) + & (pi.posting_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)