From 1135429181e2186d5d3c15fc671dcb3e3d2af18e Mon Sep 17 00:00:00 2001 From: Loic Oberle Date: Fri, 22 May 2026 12:39:41 +0200 Subject: [PATCH] refactor(territory_wise_sales):replace sql with orm (#55177) --- .../territory_wise_sales.py | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/erpnext/selling/report/territory_wise_sales/territory_wise_sales.py b/erpnext/selling/report/territory_wise_sales/territory_wise_sales.py index 48d469e795e..3e239635add 100644 --- a/erpnext/selling/report/territory_wise_sales/territory_wise_sales.py +++ b/erpnext/selling/report/territory_wise_sales/territory_wise_sales.py @@ -104,29 +104,20 @@ def get_data(filters=None): def get_opportunities(filters): - conditions = "" + orm_filters = {} if filters.get("transaction_date"): - conditions = " WHERE transaction_date between {} and {}".format( - frappe.db.escape(filters["transaction_date"][0]), - frappe.db.escape(filters["transaction_date"][1]), - ) + orm_filters["transaction_date"] = [ + "between", + [filters["transaction_date"][0], filters["transaction_date"][1]], + ] - if filters.company: - if conditions: - conditions += " AND" - else: - conditions += " WHERE" - conditions += " company = %(company)s" + if filters.get("company"): + orm_filters["company"] = filters["company"] - return frappe.db.sql( - f""" - SELECT name, territory, opportunity_amount - FROM `tabOpportunity` {conditions} - """, - filters, - as_dict=1, - ) # nosec + return frappe.get_all( + "Opportunity", fields=["name", "territory", "opportunity_amount"], filters=orm_filters + ) def get_quotations(opportunities):