def set_gl_entries_by_account(company, from_date, to_date, root_lft, root_rgt, filters, gl_entries_by_account, ignore_closing_entries=False):
 additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters)
 gl_entries = frappe.db.sql(u'select posting_date, account, debit, credit, is_opening, fiscal_year from `tabGL Entry`\n DCTB  DCTB where company=%(company)s\n DCTB  DCTB {additional_conditions}\n DCTB  DCTB and posting_date <= %(to_date)s\n DCTB  DCTB and account in (select name from `tabAccount`\n DCTB  DCTB  DCTB where lft >= %(lft)s and rgt <= %(rgt)s)\n DCTB  DCTB order by account, posting_date'.format(additional_conditions=additional_conditions), {u'company': company, u'from_date': from_date, u'to_date': to_date, u'lft': root_lft, u'rgt': root_rgt}, as_dict=True)
 for entry in gl_entries:
  gl_entries_by_account.setdefault(entry.account, []).append(entry)
 return gl_entries_by_account

def set_gl_entries_by_account ( company , from_date , to_date , root_lft , root_rgt , filters , gl_entries_by_account , ignore_closing_entries = False ) : additional_conditions = get_additional_conditions ( from_date , ignore_closing_entries , filters ) gl_entries = frappe . db . sql ( u'select posting_date, account, debit, credit, is_opening, fiscal_year from `tabGL Entry`\n DCTB  DCTB where company=%(company)s\n DCTB  DCTB {additional_conditions}\n DCTB  DCTB and posting_date <= %(to_date)s\n DCTB  DCTB and account in (select name from `tabAccount`\n DCTB  DCTB  DCTB where lft >= %(lft)s and rgt <= %(rgt)s)\n DCTB  DCTB order by account, posting_date' . format ( additional_conditions = additional_conditions ) , { u'company' : company , u'from_date' : from_date , u'to_date' : to_date , u'lft' : root_lft , u'rgt' : root_rgt } , as_dict = True ) for entry in gl_entries : gl_entries_by_account . setdefault ( entry . account , [ ] ) . append ( entry ) return gl_entries_by_account
returns a dict like { "account": [gl entries] .