mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-15 16:28:20 +00:00
fix: remove alias for order by field
(cherry picked from commit 048b87328b)
This commit is contained in:
@@ -310,8 +310,8 @@ def apply_conditions(query, pi, pii, filters):
|
||||
|
||||
def get_items(filters, additional_table_columns):
|
||||
doctype = "Purchase Invoice"
|
||||
pi = frappe.qb.DocType(doctype).as_("invoice")
|
||||
pii = frappe.qb.DocType(f"{doctype} Item").as_("invoice_item")
|
||||
pi = frappe.qb.DocType("Purchase Invoice")
|
||||
pii = frappe.qb.DocType("Purchase Invoice Item")
|
||||
Item = frappe.qb.DocType("Item")
|
||||
query = (
|
||||
frappe.qb.from_(pi)
|
||||
@@ -375,7 +375,7 @@ def get_items(filters, additional_table_columns):
|
||||
if match_conditions:
|
||||
query += " and " + match_conditions
|
||||
|
||||
query = apply_order_by_conditions(query, filters)
|
||||
query = apply_order_by_conditions(doctype, query, filters)
|
||||
|
||||
return frappe.db.sql(query, params, as_dict=True)
|
||||
|
||||
|
||||
@@ -394,15 +394,18 @@ def apply_conditions(query, si, sii, sip, filters, additional_conditions=None):
|
||||
return query
|
||||
|
||||
|
||||
def apply_order_by_conditions(query, filters):
|
||||
def apply_order_by_conditions(doctype, query, filters):
|
||||
i = f"`tab{doctype}`"
|
||||
ii = f"`tab{doctype} Item`"
|
||||
|
||||
if not filters.get("group_by"):
|
||||
query += "order by invoice.posting_date desc, invoice_item.item_group desc"
|
||||
query += f" order by {i}.posting_date desc, {ii}.item_group desc"
|
||||
elif filters.get("group_by") == "Invoice":
|
||||
query += "order by invoice_item.parent desc"
|
||||
query += f" order by {ii}.parent desc"
|
||||
elif filters.get("group_by") == "Item":
|
||||
query += "order by invoice_item.item_code"
|
||||
query += f" order by {ii}.item_code"
|
||||
elif filters.get("group_by") == "Item Group":
|
||||
query += "order by invoice_item.item_group"
|
||||
query += f" order by {ii}.item_group"
|
||||
elif filters.get("group_by") in ("Customer", "Customer Group", "Territory", "Supplier"):
|
||||
filter_field = frappe.scrub(filters.get("group_by"))
|
||||
query += f" order by {filter_field} desc"
|
||||
@@ -412,8 +415,8 @@ def apply_order_by_conditions(query, filters):
|
||||
|
||||
def get_items(filters, additional_query_columns, additional_conditions=None):
|
||||
doctype = "Sales Invoice"
|
||||
si = frappe.qb.DocType("Sales Invoice").as_("invoice")
|
||||
sii = frappe.qb.DocType("Sales Invoice Item").as_("invoice_item")
|
||||
si = frappe.qb.DocType("Sales Invoice")
|
||||
sii = frappe.qb.DocType("Sales Invoice Item")
|
||||
sip = frappe.qb.DocType("Sales Invoice Payment")
|
||||
item = frappe.qb.DocType("Item")
|
||||
|
||||
@@ -487,12 +490,12 @@ def get_items(filters, additional_query_columns, additional_conditions=None):
|
||||
from frappe.desk.reportview import build_match_conditions
|
||||
|
||||
query, params = query.walk()
|
||||
match_conditions = build_match_conditions("Sales Invoice")
|
||||
match_conditions = build_match_conditions(doctype)
|
||||
|
||||
if match_conditions:
|
||||
query += " and " + match_conditions
|
||||
|
||||
query = apply_order_by_conditions(query, filters)
|
||||
query = apply_order_by_conditions(doctype, query, filters)
|
||||
|
||||
return frappe.db.sql(query, params, as_dict=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user