From 98cc7434d286b0e13a919a8aa7a481524d200650 Mon Sep 17 00:00:00 2001 From: Vishnu VS Date: Sat, 21 Oct 2023 18:04:54 +0530 Subject: [PATCH] feat(Supplier Scorecard): added method for invoiced quantity in supplier scorecard (#37580) feat(Supplier Scorecard): added method for invoiced quantity in supplier scorecard Co-authored-by: vishnu --- .../supplier_scorecard/supplier_scorecard.py | 5 +++++ .../supplier_scorecard_variable.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) 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)