mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
Undo replace of frappe.db.sql with frappe.get_list (#14074)
This commit is contained in:
committed by
Faris Ansari
parent
265005d30d
commit
fbb6b3da5f
@@ -681,23 +681,29 @@ def get_companies():
|
||||
def get_children(doctype, parent, company, is_root=False):
|
||||
from erpnext.accounts.report.financial_statements import sort_accounts
|
||||
|
||||
parent_fieldname = 'parent_' + doctype.lower().replace(' ', '_')
|
||||
fields = [
|
||||
'name as value',
|
||||
'is_group as expandable'
|
||||
]
|
||||
filters = [['docstatus', '<', 2]]
|
||||
fieldname = frappe.db.escape(doctype.lower().replace(' ','_'))
|
||||
doctype = frappe.db.escape(doctype)
|
||||
|
||||
# root
|
||||
if is_root:
|
||||
fields += ['root_type', 'report_type', 'account_currency'] if doctype == 'Account' else []
|
||||
filters.append([parent_fieldname, '=', ''])
|
||||
filters.append(['company', '=', company])
|
||||
|
||||
fields = ", root_type, report_type, account_currency" if doctype=="Account" else ""
|
||||
acc = frappe.db.sql(""" select
|
||||
name as value, is_group as expandable {fields}
|
||||
from `tab{doctype}`
|
||||
where ifnull(`parent_{fieldname}`,'') = ''
|
||||
and `company` = %s and docstatus<2
|
||||
order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype),
|
||||
company, as_dict=1)
|
||||
else:
|
||||
fields += ['account_currency'] if doctype == 'Account' else []
|
||||
fields += [parent_fieldname + ' as parent']
|
||||
|
||||
|
||||
acc = frappe.get_list(doctype, fields=fields, filters=filters)
|
||||
# other
|
||||
fields = ", account_currency" if doctype=="Account" else ""
|
||||
acc = frappe.db.sql("""select
|
||||
name as value, is_group as expandable, parent_{fieldname} as parent {fields}
|
||||
from `tab{doctype}`
|
||||
where ifnull(`parent_{fieldname}`,'') = %s
|
||||
and docstatus<2
|
||||
order by name""".format(fields=fields, fieldname=fieldname, doctype=doctype),
|
||||
parent, as_dict=1)
|
||||
|
||||
if doctype == 'Account':
|
||||
sort_accounts(acc, is_root, key="value")
|
||||
|
||||
Reference in New Issue
Block a user