GL report does not sort

I was trying to include some custom fields in Accounts → Main Reports → General Ledger and sort on them and then noticed that the report does not sort as instructed in the original function.

In general_ledger.py there is this function

def get_gl_entries(filters):
group_by_condition = “group by voucher_type, voucher_no, account, cost_center”
if filters.get(“group_by_voucher”) else “group by name”

gl_entries = frappe.db.sql(“”“select posting_date, account, party_type, party,
sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit,
voucher_type, voucher_no, cost_center, remarks, against, is_opening
from tabGL Entry
where company=%(company)s {conditions}
{group_by_condition}
order by posting_date, account”“”
.format(conditions=get_conditions(filters), group_by_condition=group_by_condition),
filters, as_dict=1)
return gl_entries

Despite of “order by” part, when I look at my journals they are not sorted that way but (probably) by the time they were created.

Am I misunderstanding something or how can this be?

Thanks.

Yeah if there are no filters, group by it seems to be an issue.

The sort is now working, thanks.

However, I am now not able to include the custom field “Designation” in the report.

I tried

def get_columns(filters):
	columns = [
		_("Posting Date") + ":Date:90", _("Designation") + "::90", _("Account") + ":Link/Account:200",
...

and

def get_glentries(filters): 
...
gl_entries = frappe.db.sql("""select posting_date, designation, account, party_type, party,
...

As soon as I add the bits about my custom field in the above two lines - I get an empty list in the report. So, I am now worse off than I was when the sort did not work, previously I saw the data in my custom field :confused:

Please help.

You will have to read the code to understand. Unfortunately its a complex piece of code.