mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
refactor(territory_wise_sales):replace sql with orm (#55177)
This commit is contained in:
@@ -104,29 +104,20 @@ def get_data(filters=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_opportunities(filters):
|
def get_opportunities(filters):
|
||||||
conditions = ""
|
orm_filters = {}
|
||||||
|
|
||||||
if filters.get("transaction_date"):
|
if filters.get("transaction_date"):
|
||||||
conditions = " WHERE transaction_date between {} and {}".format(
|
orm_filters["transaction_date"] = [
|
||||||
frappe.db.escape(filters["transaction_date"][0]),
|
"between",
|
||||||
frappe.db.escape(filters["transaction_date"][1]),
|
[filters["transaction_date"][0], filters["transaction_date"][1]],
|
||||||
)
|
]
|
||||||
|
|
||||||
if filters.company:
|
if filters.get("company"):
|
||||||
if conditions:
|
orm_filters["company"] = filters["company"]
|
||||||
conditions += " AND"
|
|
||||||
else:
|
|
||||||
conditions += " WHERE"
|
|
||||||
conditions += " company = %(company)s"
|
|
||||||
|
|
||||||
return frappe.db.sql(
|
return frappe.get_all(
|
||||||
f"""
|
"Opportunity", fields=["name", "territory", "opportunity_amount"], filters=orm_filters
|
||||||
SELECT name, territory, opportunity_amount
|
)
|
||||||
FROM `tabOpportunity` {conditions}
|
|
||||||
""",
|
|
||||||
filters,
|
|
||||||
as_dict=1,
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
|
|
||||||
def get_quotations(opportunities):
|
def get_quotations(opportunities):
|
||||||
|
|||||||
Reference in New Issue
Block a user