Merge pull request #13918 from manassolanki/item-level-defualts

[enhancement] add the item defaults in the child-table for multi-company
diff --git a/erpnext/accounts/doctype/budget_account/budget_account.json b/erpnext/accounts/doctype/budget_account/budget_account.json
index 172e092..ead0761 100644
--- a/erpnext/accounts/doctype/budget_account/budget_account.json
+++ b/erpnext/accounts/doctype/budget_account/budget_account.json
@@ -73,7 +73,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/c_form_invoice_detail/c_form_invoice_detail.json b/erpnext/accounts/doctype/c_form_invoice_detail/c_form_invoice_detail.json
index e78620e..9da4411 100644
--- a/erpnext/accounts/doctype/c_form_invoice_detail/c_form_invoice_detail.json
+++ b/erpnext/accounts/doctype/c_form_invoice_detail/c_form_invoice_detail.json
@@ -150,7 +150,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.json b/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.json
index 51da9c0..e9993c3 100644
--- a/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.json
+++ b/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.json
@@ -1020,7 +1020,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json
index 4e568f1..3eb0d74 100644
--- a/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json
+++ b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json
@@ -42,7 +42,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json
index 8b03e2e..9609e3d 100644
--- a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json
+++ b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json
@@ -109,7 +109,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.json b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.json
index 2340340..14f2d80 100644
--- a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.json
+++ b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.json
@@ -109,7 +109,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/monthly_distribution_percentage/monthly_distribution_percentage.json b/erpnext/accounts/doctype/monthly_distribution_percentage/monthly_distribution_percentage.json
index 373d090..8c9fc5e 100644
--- a/erpnext/accounts/doctype/monthly_distribution_percentage/monthly_distribution_percentage.json
+++ b/erpnext/accounts/doctype/monthly_distribution_percentage/monthly_distribution_percentage.json
@@ -68,7 +68,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/party_account/party_account.json b/erpnext/accounts/doctype/party_account/party_account.json
index a83bb26..aa32d95 100644
--- a/erpnext/accounts/doctype/party_account/party_account.json
+++ b/erpnext/accounts/doctype/party_account/party_account.json
@@ -66,7 +66,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/payment_entry_deduction/payment_entry_deduction.json b/erpnext/accounts/doctype/payment_entry_deduction/payment_entry_deduction.json
index 10e147e..d69a5eb 100644
--- a/erpnext/accounts/doctype/payment_entry_deduction/payment_entry_deduction.json
+++ b/erpnext/accounts/doctype/payment_entry_deduction/payment_entry_deduction.json
@@ -93,7 +93,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json
index bf18fca..24b366c 100644
--- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json
+++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json
@@ -220,7 +220,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json
index fc4edae..b211b50 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json
@@ -391,7 +391,7 @@
  "icon": "fa fa-resize-horizontal", 
  "idx": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/payment_reconciliation_invoice/payment_reconciliation_invoice.json b/erpnext/accounts/doctype/payment_reconciliation_invoice/payment_reconciliation_invoice.json
index ab8761a..ce7ce98 100644
--- a/erpnext/accounts/doctype/payment_reconciliation_invoice/payment_reconciliation_invoice.json
+++ b/erpnext/accounts/doctype/payment_reconciliation_invoice/payment_reconciliation_invoice.json
@@ -162,7 +162,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json b/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
index 57fce65..ba6f100 100644
--- a/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
+++ b/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
@@ -318,7 +318,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json b/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json
index 4f6a675..3ad450b 100644
--- a/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json
+++ b/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json
@@ -45,7 +45,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/pos_item_group/pos_item_group.json b/erpnext/accounts/doctype/pos_item_group/pos_item_group.json
index b278765..860c449 100644
--- a/erpnext/accounts/doctype/pos_item_group/pos_item_group.json
+++ b/erpnext/accounts/doctype/pos_item_group/pos_item_group.json
@@ -45,7 +45,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 61b6edf..08e3d10 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -812,4 +812,3 @@
 def make_inter_company_sales_invoice(source_name, target_doc=None):
 	from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_invoice
 	return make_inter_company_invoice("Purchase Invoice", source_name, target_doc)
-
diff --git a/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json b/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json
index 49582a4..5801b17 100644
--- a/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json
+++ b/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json
@@ -215,7 +215,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.json b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.json
index 50426df..bc42630 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.json
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.json
@@ -217,7 +217,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/salary_component_account/salary_component_account.json b/erpnext/accounts/doctype/salary_component_account/salary_component_account.json
index 6ba820e..23dc6c4 100644
--- a/erpnext/accounts/doctype/salary_component_account/salary_component_account.json
+++ b/erpnext/accounts/doctype/salary_component_account/salary_component_account.json
@@ -71,7 +71,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json b/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json
index dbbe368..14bf4d8 100644
--- a/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json
+++ b/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json
@@ -215,7 +215,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json b/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json
index a0a6312..50eed24 100644
--- a/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json
+++ b/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json
@@ -134,7 +134,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json
index 894d5ab..29e15d1 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.json
@@ -216,7 +216,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/accounts/doctype/shipping_rule_condition/shipping_rule_condition.json b/erpnext/accounts/doctype/shipping_rule_condition/shipping_rule_condition.json
index a6df2ac..0a06f57 100644
--- a/erpnext/accounts/doctype/shipping_rule_condition/shipping_rule_condition.json
+++ b/erpnext/accounts/doctype/shipping_rule_condition/shipping_rule_condition.json
@@ -89,7 +89,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/doctype/shipping_rule_country/shipping_rule_country.json b/erpnext/accounts/doctype/shipping_rule_country/shipping_rule_country.json
index fe28fcb..46fd377 100644
--- a/erpnext/accounts/doctype/shipping_rule_country/shipping_rule_country.json
+++ b/erpnext/accounts/doctype/shipping_rule_country/shipping_rule_country.json
@@ -42,7 +42,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index a33f867..f53f924 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -681,23 +681,29 @@
 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")
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.py b/erpnext/agriculture/doctype/land_unit/land_unit.py
index 35bda1c..f577eca 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.py
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.py
@@ -169,10 +169,11 @@
 	if is_root:
 		parent = ''
 
-	land_units = frappe.get_list(doctype,
-		fields = ['name as value', 'is_group as expandable'],
-		filters= [['parent_land_unit', '=', parent]],
-		order_by='name')
+	land_units = frappe.db.sql("""select name as value,
+		is_group as expandable
+		from `tabLand Unit`
+		where ifnull(`parent_land_unit`,'') = %s
+		order by name""", (parent), as_dict=1)
 
 	# return nodes
 	return land_units
diff --git a/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json b/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json
index a7ae8a6..6833a4a 100644
--- a/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json
+++ b/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json
@@ -715,7 +715,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json
index 181b214..52b6778 100644
--- a/erpnext/buying/doctype/supplier/supplier.json
+++ b/erpnext/buying/doctype/supplier/supplier.json
@@ -1322,7 +1322,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2018-05-11 15:15:19.912308", 
+ "modified": "2018-05-16 15:15:19.912308", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier", 
diff --git a/erpnext/crm/doctype/opportunity_item/opportunity_item.json b/erpnext/crm/doctype/opportunity_item/opportunity_item.json
index 0845d42..ee7c1e3 100644
--- a/erpnext/crm/doctype/opportunity_item/opportunity_item.json
+++ b/erpnext/crm/doctype/opportunity_item/opportunity_item.json
@@ -407,7 +407,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/appraisal_goal/appraisal_goal.json b/erpnext/hr/doctype/appraisal_goal/appraisal_goal.json
index 49fe105..f22969b 100644
--- a/erpnext/hr/doctype/appraisal_goal/appraisal_goal.json
+++ b/erpnext/hr/doctype/appraisal_goal/appraisal_goal.json
@@ -202,7 +202,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/appraisal_template/appraisal_template.json b/erpnext/hr/doctype/appraisal_template/appraisal_template.json
index 97402ac..ac6e400 100644
--- a/erpnext/hr/doctype/appraisal_template/appraisal_template.json
+++ b/erpnext/hr/doctype/appraisal_template/appraisal_template.json
@@ -108,7 +108,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/appraisal_template_goal/appraisal_template_goal.json b/erpnext/hr/doctype/appraisal_template_goal/appraisal_template_goal.json
index d11ec64..34ea5d8 100644
--- a/erpnext/hr/doctype/appraisal_template_goal/appraisal_template_goal.json
+++ b/erpnext/hr/doctype/appraisal_template_goal/appraisal_template_goal.json
@@ -73,7 +73,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/branch/branch.json b/erpnext/hr/doctype/branch/branch.json
index 609456c..221b522 100644
--- a/erpnext/hr/doctype/branch/branch.json
+++ b/erpnext/hr/doctype/branch/branch.json
@@ -44,7 +44,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/department/test_records.json b/erpnext/hr/doctype/department/test_records.json
index 5bb5871..654925e 100644
--- a/erpnext/hr/doctype/department/test_records.json
+++ b/erpnext/hr/doctype/department/test_records.json
@@ -1,4 +1,4 @@
 [
-	{"doctype":"Department", "department_name":"_Test Department"},
-	{"doctype":"Department", "department_name":"_Test Department 1"}
+	{"doctype":"Department", "department_name":"_Test Department", "company": "_Test Company"},
+	{"doctype":"Department", "department_name":"_Test Department 1", "company": "_Test Company"}
 ]
\ No newline at end of file
diff --git a/erpnext/hr/doctype/designation/designation.json b/erpnext/hr/doctype/designation/designation.json
index 9315cfd..1d4a3cf 100644
--- a/erpnext/hr/doctype/designation/designation.json
+++ b/erpnext/hr/doctype/designation/designation.json
@@ -77,7 +77,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py
index 93f6532..824ddf5 100755
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -318,26 +318,26 @@
 
 @frappe.whitelist()
 def get_children(doctype, parent=None, company=None, is_root=False, is_tree=False):
-	filters = [['company', '=', company]]
-	fields = ['name as value', 'employee_name as title']
+	condition = ''
 
 	if is_root:
-		parent = ''
+		parent = ""
 	if parent and company and parent!=company:
-		filters.append(['reports_to', '=', parent])
+		condition = ' and reports_to = "{0}"'.format(frappe.db.escape(parent))
 	else:
-		filters.append(['reports_to', '=', ''])
+		condition = ' and ifnull(reports_to, "")=""'
 
-	employees = frappe.get_list(doctype, fields=fields,
-		filters=filters, order_by='name')
+	employee = frappe.db.sql("""
+		select
+			name as value, employee_name as title,
+			exists(select name from `tabEmployee` where reports_to=emp.name) as expandable
+		from
+			`tabEmployee` emp
+		where company='{company}' {condition} order by name"""
+		.format(company=company, condition=condition),  as_dict=1)
 
-	for employee in employees:
-		is_expandable = frappe.get_all(doctype, filters=[
-			['reports_to', '=', employee.get('value')]
-		])
-		employee.expandable = 1 if is_expandable else 0
-
-	return employees
+	# return employee
+	return employee
 
 
 def on_doctype_update():
diff --git a/erpnext/hr/doctype/employee/test_records.json b/erpnext/hr/doctype/employee/test_records.json
index 087265f..0bfd2aa 100644
--- a/erpnext/hr/doctype/employee/test_records.json
+++ b/erpnext/hr/doctype/employee/test_records.json
@@ -3,7 +3,7 @@
   "company": "_Test Company", 
   "date_of_birth": "1980-01-01", 
   "date_of_joining": "2010-01-01", 
-  "department": "_Test Department", 
+  "department": "_Test Department - _TC", 
   "doctype": "Employee", 
   "employee_name": "_Test Employee", 
   "gender": "Female", 
@@ -15,7 +15,7 @@
   "company": "_Test Company", 
   "date_of_birth": "1980-01-01", 
   "date_of_joining": "2010-01-01", 
-  "department": "_Test Department 1", 
+  "department": "_Test Department 1 - _TC", 
   "doctype": "Employee", 
   "employee_name": "_Test Employee 1", 
   "gender": "Male", 
@@ -27,7 +27,7 @@
   "company": "_Test Company", 
   "date_of_birth": "1980-01-01", 
   "date_of_joining": "2010-01-01", 
-  "department": "_Test Department 1", 
+  "department": "_Test Department 1 - _TC", 
   "doctype": "Employee", 
   "employee_name": "_Test Employee 2", 
   "gender": "Male", 
diff --git a/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.json b/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
index f31bcf8..256e056 100644
--- a/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
+++ b/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
@@ -235,7 +235,7 @@
  "hide_toolbar": 1, 
  "idx": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/employee_education/employee_education.json b/erpnext/hr/doctype/employee_education/employee_education.json
index e41c6ca..ef216e3 100644
--- a/erpnext/hr/doctype/employee_education/employee_education.json
+++ b/erpnext/hr/doctype/employee_education/employee_education.json
@@ -174,7 +174,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/employee_external_work_history/employee_external_work_history.json b/erpnext/hr/doctype/employee_external_work_history/employee_external_work_history.json
index fcabbbc..f357b20 100644
--- a/erpnext/hr/doctype/employee_external_work_history/employee_external_work_history.json
+++ b/erpnext/hr/doctype/employee_external_work_history/employee_external_work_history.json
@@ -172,7 +172,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/employee_internal_work_history/employee_internal_work_history.json b/erpnext/hr/doctype/employee_internal_work_history/employee_internal_work_history.json
index 3d277af..98632b6 100644
--- a/erpnext/hr/doctype/employee_internal_work_history/employee_internal_work_history.json
+++ b/erpnext/hr/doctype/employee_internal_work_history/employee_internal_work_history.json
@@ -148,7 +148,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/employment_type/employment_type.json b/erpnext/hr/doctype/employment_type/employment_type.json
index da84ce4..9dcae3c 100644
--- a/erpnext/hr/doctype/employment_type/employment_type.json
+++ b/erpnext/hr/doctype/employment_type/employment_type.json
@@ -48,7 +48,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/expense_claim_account/expense_claim_account.json b/erpnext/hr/doctype/expense_claim_account/expense_claim_account.json
index a2bbe0b..c7d71d3 100644
--- a/erpnext/hr/doctype/expense_claim_account/expense_claim_account.json
+++ b/erpnext/hr/doctype/expense_claim_account/expense_claim_account.json
@@ -68,7 +68,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json b/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json
index f59111a..b60ba5f 100644
--- a/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json
+++ b/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json
@@ -101,7 +101,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/holiday/holiday.json b/erpnext/hr/doctype/holiday/holiday.json
index cc65631..6498530 100644
--- a/erpnext/hr/doctype/holiday/holiday.json
+++ b/erpnext/hr/doctype/holiday/holiday.json
@@ -68,7 +68,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/interest/interest.json b/erpnext/hr/doctype/interest/interest.json
index 955c40f..d6d2342 100644
--- a/erpnext/hr/doctype/interest/interest.json
+++ b/erpnext/hr/doctype/interest/interest.json
@@ -42,7 +42,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.json b/erpnext/hr/doctype/job_applicant/job_applicant.json
index 2a97f28..dc8d82c 100644
--- a/erpnext/hr/doctype/job_applicant/job_applicant.json
+++ b/erpnext/hr/doctype/job_applicant/job_applicant.json
@@ -249,7 +249,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py
index b467350..9b02559 100644
--- a/erpnext/hr/doctype/leave_application/test_leave_application.py
+++ b/erpnext/hr/doctype/leave_application/test_leave_application.py
@@ -71,7 +71,7 @@
 		add_role("test1@example.com", "Leave Approver")
 		clear_user_permissions_for_doctype("Employee")
 
-		frappe.db.set_value("Department", "_Test Department",
+		frappe.db.set_value("Department", "_Test Department - _TC",
 			"leave_block_list", "_Test Leave Block List")
 
 		make_allocation_record()
@@ -214,7 +214,7 @@
 		frappe.db.set_value("Leave Block List", "_Test Leave Block List",
 			"applies_to_all_departments", 1)
 		frappe.db.set_value("Employee", "_T-Employee-00002", "department",
-			"_Test Department")
+			"_Test Department - _TC")
 
 		frappe.set_user("test1@example.com")
 		application.insert()
diff --git a/erpnext/hr/doctype/leave_block_list/leave_block_list.json b/erpnext/hr/doctype/leave_block_list/leave_block_list.json
index 16dbda8..fdb975b 100644
--- a/erpnext/hr/doctype/leave_block_list/leave_block_list.json
+++ b/erpnext/hr/doctype/leave_block_list/leave_block_list.json
@@ -207,7 +207,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/leave_block_list/test_leave_block_list.py b/erpnext/hr/doctype/leave_block_list/test_leave_block_list.py
index 3abe406..0eb69a5 100644
--- a/erpnext/hr/doctype/leave_block_list/test_leave_block_list.py
+++ b/erpnext/hr/doctype/leave_block_list/test_leave_block_list.py
@@ -14,20 +14,20 @@
 
 	def test_get_applicable_block_dates(self):
 		frappe.set_user("test@example.com")
-		frappe.db.set_value("Department", "_Test Department", "leave_block_list",
+		frappe.db.set_value("Department", "_Test Department - _TC", "leave_block_list",
 			"_Test Leave Block List")
 		self.assertTrue(getdate("2013-01-02") in
 			[d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03")])
 
 	def test_get_applicable_block_dates_for_allowed_user(self):
 		frappe.set_user("test1@example.com")
-		frappe.db.set_value("Department", "_Test Department 1", "leave_block_list",
+		frappe.db.set_value("Department", "_Test Department 1 - _TC", "leave_block_list",
 			"_Test Leave Block List")
 		self.assertEqual([], [d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03")])
 
 	def test_get_applicable_block_dates_all_lists(self):
 		frappe.set_user("test1@example.com")
-		frappe.db.set_value("Department", "_Test Department 1", "leave_block_list",
+		frappe.db.set_value("Department", "_Test Department 1 - _TC", "leave_block_list",
 			"_Test Leave Block List")
 		self.assertTrue(getdate("2013-01-02") in
 			[d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03", all_lists=True)])
diff --git a/erpnext/hr/doctype/leave_block_list_allow/leave_block_list_allow.json b/erpnext/hr/doctype/leave_block_list_allow/leave_block_list_allow.json
index fbc2991..fe10c78 100644
--- a/erpnext/hr/doctype/leave_block_list_allow/leave_block_list_allow.json
+++ b/erpnext/hr/doctype/leave_block_list_allow/leave_block_list_allow.json
@@ -42,7 +42,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/leave_block_list_date/leave_block_list_date.json b/erpnext/hr/doctype/leave_block_list_date/leave_block_list_date.json
index 1d0ac01..dbb9039 100644
--- a/erpnext/hr/doctype/leave_block_list_date/leave_block_list_date.json
+++ b/erpnext/hr/doctype/leave_block_list_date/leave_block_list_date.json
@@ -67,7 +67,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/offer_term/offer_term.json b/erpnext/hr/doctype/offer_term/offer_term.json
index cb059a1..3b7bd42 100644
--- a/erpnext/hr/doctype/offer_term/offer_term.json
+++ b/erpnext/hr/doctype/offer_term/offer_term.json
@@ -42,7 +42,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/salary_component/salary_component.json b/erpnext/hr/doctype/salary_component/salary_component.json
index f08b1d7..cf85af4 100644
--- a/erpnext/hr/doctype/salary_component/salary_component.json
+++ b/erpnext/hr/doctype/salary_component/salary_component.json
@@ -114,6 +114,70 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:doc.type==\"Earning\"", 
+   "fieldname": "is_tax_applicable", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Tax Applicable", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "translatable": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "1", 
+   "fieldname": "is_payable", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Payable", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "translatable": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -554,6 +618,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "is_payable", 
    "fieldname": "section_break_5", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -924,320 +989,6 @@
    "set_only_once": 0, 
    "translatable": 0, 
    "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "condition_and_formula", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Condition and Formula", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "condition", 
-   "fieldtype": "Code", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Condition", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "If selected, the value specified or calculated in this component will not contribute to the earnings or deductions. However, it's value can be referenced by other components that can be added or deducted. ", 
-   "fieldname": "statistical_component", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Statistical Component", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "depends_on_lwp", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Depends on Leave Without Pay", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "do_not_include_in_total", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Do not include in total", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "1", 
-   "fieldname": "amount_based_on_formula", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Amount based on formula", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.amount_based_on_formula!==0", 
-   "fieldname": "formula", 
-   "fieldtype": "Code", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Formula", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.amount_based_on_formula!==1", 
-   "fieldname": "amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Amount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_28", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "help", 
-   "fieldtype": "HTML", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Help", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "<h3>Help</h3>\n\n<p>Notes:</p>\n\n<ol>\n<li>Use field <code>base</code> for using base salary of the Employee</li>\n<li>Use Salary Component abbreviations in conditions and formulas. <code>BS = Basic Salary</code></li>\n<li>Use field name for employee details in conditions and formulas. <code>Employment Type = employment_type</code><code>Branch = branch</code></li>\n<li>Use field name from Salary Slip in conditions and formulas. <code>Payment Days = payment_days</code><code>Leave without pay = leave_without_pay</code></li>\n<li>Direct Amount can also be entered based on Condtion. See example 3</li></ol>\n\n<h4>Examples</h4>\n<ol>\n<li>Calculating Basic Salary based on <code>base</code>\n<pre><code>Condition: base &lt; 10000</code></pre>\n<pre><code>Formula: base * .2</code></pre></li>\n<li>Calculating HRA based on Basic Salary<code>BS</code> \n<pre><code>Condition: BS &gt; 2000</code></pre>\n<pre><code>Formula: BS * .1</code></pre></li>\n<li>Calculating TDS based on Employment Type<code>employment_type</code> \n<pre><code>Condition: employment_type==\"Intern\"</code></pre>\n<pre><code>Amount: 1000</code></pre></li>\n</ol>", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
   }
  ], 
  "has_web_view": 0, 
@@ -1251,7 +1002,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2018-05-09 17:35:11.073733", 
+ "modified": "2018-05-16 12:15:43.117948", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Component", 
@@ -1286,4 +1037,4 @@
  "sort_order": "DESC", 
  "track_changes": 0, 
  "track_seen": 0
-}
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_slip_timesheet/salary_slip_timesheet.json b/erpnext/hr/doctype/salary_slip_timesheet/salary_slip_timesheet.json
index 52f829e..7a9393c 100644
--- a/erpnext/hr/doctype/salary_slip_timesheet/salary_slip_timesheet.json
+++ b/erpnext/hr/doctype/salary_slip_timesheet/salary_slip_timesheet.json
@@ -67,7 +67,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json b/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json
index 0e238d3..6c7a61c 100644
--- a/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json
+++ b/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json
@@ -194,7 +194,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/training_feedback/training_feedback.json b/erpnext/hr/doctype/training_feedback/training_feedback.json
index ece6ed1..80c1005 100644
--- a/erpnext/hr/doctype/training_feedback/training_feedback.json
+++ b/erpnext/hr/doctype/training_feedback/training_feedback.json
@@ -309,7 +309,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/hr/doctype/training_result_employee/training_result_employee.json b/erpnext/hr/doctype/training_result_employee/training_result_employee.json
index 477a8e6..c5e791a 100644
--- a/erpnext/hr/doctype/training_result_employee/training_result_employee.json
+++ b/erpnext/hr/doctype/training_result_employee/training_result_employee.json
@@ -233,7 +233,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/hr/doctype/vehicle_service/vehicle_service.json b/erpnext/hr/doctype/vehicle_service/vehicle_service.json
index 635a0b6..7d9d0df 100644
--- a/erpnext/hr/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/hr/doctype/vehicle_service/vehicle_service.json
@@ -131,7 +131,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/maintenance/doctype/maintenance_schedule_detail/maintenance_schedule_detail.json b/erpnext/maintenance/doctype/maintenance_schedule_detail/maintenance_schedule_detail.json
index 0a74436..7cd3086 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule_detail/maintenance_schedule_detail.json
+++ b/erpnext/maintenance/doctype/maintenance_schedule_detail/maintenance_schedule_detail.json
@@ -202,7 +202,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json b/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json
index e55f562..d2a0ffa 100644
--- a/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json
+++ b/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json
@@ -328,7 +328,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index c09ea11..bbf8f71 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -626,28 +626,18 @@
 		return
 
 	if frappe.form_dict.parent:
-		bom_items = frappe.get_list('BOM Item',
-			fields=['item_code', 'bom_no as value', 'stock_qty'],
-			filters=[['parent', '=', frappe.form_dict.parent]],
-			order_by='idx')
-
-		item_names = tuple(d.get('item_code') for d in bom_items)
-
-		items = frappe.get_list('Item',
-			fields=['image', 'description', 'name'],
-			filters=[['name', 'in', item_names]]) # to get only required item dicts
-
-		for bom_item in bom_items:
-			# extend bom_item dict with respective item dict
-			bom_item.update(
-				# returns an item dict from items list which matches with item_code
-				(item for item in items if item.get('name')
-					== bom_item.get('item_code')).next()
-			)
-			bom_item.expandable = 0 if bom_item.value in ('', None)  else 1
-
-		return bom_items
-
+		return frappe.db.sql("""select
+			bom_item.item_code,
+			bom_item.bom_no as value,
+			bom_item.stock_qty,
+			if(ifnull(bom_item.bom_no, "")!="", 1, 0) as expandable,
+			item.image,
+			item.description
+			from `tabBOM Item` bom_item, tabItem item
+			where bom_item.parent=%s
+			and bom_item.item_code = item.name
+			order by bom_item.idx
+			""", frappe.form_dict.parent, as_dict=True)
 
 def get_boms_in_bottom_up_order(bom_no=None):
 	def _get_parent(bom_no):
diff --git a/erpnext/manufacturing/doctype/bom_website_item/bom_website_item.json b/erpnext/manufacturing/doctype/bom_website_item/bom_website_item.json
index 7df728b..b6e20af 100644
--- a/erpnext/manufacturing/doctype/bom_website_item/bom_website_item.json
+++ b/erpnext/manufacturing/doctype/bom_website_item/bom_website_item.json
@@ -154,7 +154,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/manufacturing/doctype/bom_website_operation/bom_website_operation.json b/erpnext/manufacturing/doctype/bom_website_operation/bom_website_operation.json
index 8f28dd7..3fad2ef 100644
--- a/erpnext/manufacturing/doctype/bom_website_operation/bom_website_operation.json
+++ b/erpnext/manufacturing/doctype/bom_website_operation/bom_website_operation.json
@@ -154,7 +154,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/manufacturing/doctype/operation/operation.json b/erpnext/manufacturing/doctype/operation/operation.json
index 69eb449..c231fba 100644
--- a/erpnext/manufacturing/doctype/operation/operation.json
+++ b/erpnext/manufacturing/doctype/operation/operation.json
@@ -103,7 +103,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/manufacturing/doctype/workstation_working_hour/workstation_working_hour.json b/erpnext/manufacturing/doctype/workstation_working_hour/workstation_working_hour.json
index 89ca714..a79182f 100644
--- a/erpnext/manufacturing/doctype/workstation_working_hour/workstation_working_hour.json
+++ b/erpnext/manufacturing/doctype/workstation_working_hour/workstation_working_hour.json
@@ -129,7 +129,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/portal/doctype/homepage/homepage.json b/erpnext/portal/doctype/homepage/homepage.json
index e0e47d1..81433b1 100644
--- a/erpnext/portal/doctype/homepage/homepage.json
+++ b/erpnext/portal/doctype/homepage/homepage.json
@@ -199,7 +199,6 @@
  "idx": 0,
  "image_view": 0,
  "in_create": 0,
- "in_dialog": 0,
  "is_submittable": 0,
  "issingle": 1,
  "istable": 0,
diff --git a/erpnext/portal/doctype/homepage_featured_product/homepage_featured_product.json b/erpnext/portal/doctype/homepage_featured_product/homepage_featured_product.json
index 870c8b1..c8b4ae9 100644
--- a/erpnext/portal/doctype/homepage_featured_product/homepage_featured_product.json
+++ b/erpnext/portal/doctype/homepage_featured_product/homepage_featured_product.json
@@ -280,7 +280,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/projects/doctype/activity_cost/activity_cost.json b/erpnext/projects/doctype/activity_cost/activity_cost.json
index 9d812dd..78a66c4 100644
--- a/erpnext/projects/doctype/activity_cost/activity_cost.json
+++ b/erpnext/projects/doctype/activity_cost/activity_cost.json
@@ -274,7 +274,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/projects/doctype/dependent_task/dependent_task.json b/erpnext/projects/doctype/dependent_task/dependent_task.json
index 18e6c0d..e00a2b2 100644
--- a/erpnext/projects/doctype/dependent_task/dependent_task.json
+++ b/erpnext/projects/doctype/dependent_task/dependent_task.json
@@ -43,7 +43,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/projects/doctype/project_user/project_user.json b/erpnext/projects/doctype/project_user/project_user.json
index ea57589..a7cc810 100644
--- a/erpnext/projects/doctype/project_user/project_user.json
+++ b/erpnext/projects/doctype/project_user/project_user.json
@@ -67,7 +67,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index c86e699..fcaa344 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -186,25 +186,27 @@
 
 @frappe.whitelist()
 def get_children(doctype, parent, task=None, project=None, is_root=False):
-
-	filters = [['docstatus', '<', '2']]
+	conditions = ''
 
 	if task:
-		filters.append(['parent_task', '=', task])
+		# via filters
+		conditions += ' and parent_task = "{0}"'.format(frappe.db.escape(task))
 	elif parent and not is_root:
 		# via expand child
-		filters.append(['parent_task', '=', parent])
+		conditions += ' and parent_task = "{0}"'.format(frappe.db.escape(parent))
 	else:
-		filters.append(['parent_task', '=', ''])
+		conditions += ' and ifnull(parent_task, "")=""'
 
 	if project:
-		filters.append(['project', '=', project])
+		conditions += ' and project = "{0}"'.format(frappe.db.escape(project))
 
-	tasks = frappe.get_list(doctype, fields=[
-		'name as value',
-		'subject as title',
-		'is_group as expandable'
-	], filters=filters, order_by='name')
+	tasks = frappe.db.sql("""select name as value,
+		subject as title,
+		is_group as expandable
+		from `tabTask`
+		where docstatus < 2
+		{conditions}
+		order by name""".format(conditions=conditions), as_dict=1)
 
 	# return tasks
 	return tasks
diff --git a/erpnext/projects/doctype/task_depends_on/task_depends_on.json b/erpnext/projects/doctype/task_depends_on/task_depends_on.json
index 25657af..dbbe9d3 100644
--- a/erpnext/projects/doctype/task_depends_on/task_depends_on.json
+++ b/erpnext/projects/doctype/task_depends_on/task_depends_on.json
@@ -133,7 +133,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/selling/doctype/industry_type/industry_type.json b/erpnext/selling/doctype/industry_type/industry_type.json
index 027626c..f4fcae4 100644
--- a/erpnext/selling/doctype/industry_type/industry_type.json
+++ b/erpnext/selling/doctype/industry_type/industry_type.json
@@ -44,7 +44,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/selling/doctype/installation_note_item/installation_note_item.json b/erpnext/selling/doctype/installation_note_item/installation_note_item.json
index 17bf278..79bcf10 100644
--- a/erpnext/selling/doctype/installation_note_item/installation_note_item.json
+++ b/erpnext/selling/doctype/installation_note_item/installation_note_item.json
@@ -238,7 +238,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/selling/doctype/lead_source/lead_source.json b/erpnext/selling/doctype/lead_source/lead_source.json
index e677915..868f6d1 100644
--- a/erpnext/selling/doctype/lead_source/lead_source.json
+++ b/erpnext/selling/doctype/lead_source/lead_source.json
@@ -69,7 +69,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/selling/doctype/product_bundle_item/product_bundle_item.json b/erpnext/selling/doctype/product_bundle_item/product_bundle_item.json
index d31b5fb..38f51de 100644
--- a/erpnext/selling/doctype/product_bundle_item/product_bundle_item.json
+++ b/erpnext/selling/doctype/product_bundle_item/product_bundle_item.json
@@ -169,7 +169,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/selling/doctype/sales_team/sales_team.json b/erpnext/selling/doctype/sales_team/sales_team.json
index fcd61a1..c77f9f4 100644
--- a/erpnext/selling/doctype/sales_team/sales_team.json
+++ b/erpnext/selling/doctype/sales_team/sales_team.json
@@ -157,7 +157,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/setup/doctype/authorization_control/authorization_control.json b/erpnext/setup/doctype/authorization_control/authorization_control.json
index 43afc06..823ff26 100644
--- a/erpnext/setup/doctype/authorization_control/authorization_control.json
+++ b/erpnext/setup/doctype/authorization_control/authorization_control.json
@@ -11,7 +11,7 @@
  "hide_toolbar": 0, 
  "idx": 1, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/authorization_rule/authorization_rule.json b/erpnext/setup/doctype/authorization_rule/authorization_rule.json
index 70047bc..56df330 100644
--- a/erpnext/setup/doctype/authorization_rule/authorization_rule.json
+++ b/erpnext/setup/doctype/authorization_rule/authorization_rule.json
@@ -558,7 +558,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/brand/brand.json b/erpnext/setup/doctype/brand/brand.json
index 8d4ba74..064eff6 100644
--- a/erpnext/setup/doctype/brand/brand.json
+++ b/erpnext/setup/doctype/brand/brand.json
@@ -79,7 +79,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/customer_group/customer_group.json b/erpnext/setup/doctype/customer_group/customer_group.json
index 062a49a..3392c6c 100644
--- a/erpnext/setup/doctype/customer_group/customer_group.json
+++ b/erpnext/setup/doctype/customer_group/customer_group.json
@@ -379,7 +379,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/email_digest/email_digest.json b/erpnext/setup/doctype/email_digest/email_digest.json
index a75a59a..12f275c 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.json
+++ b/erpnext/setup/doctype/email_digest/email_digest.json
@@ -1073,7 +1073,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/global_defaults/global_defaults.json b/erpnext/setup/doctype/global_defaults/global_defaults.json
index ce3f2cf..a6c5964 100644
--- a/erpnext/setup/doctype/global_defaults/global_defaults.json
+++ b/erpnext/setup/doctype/global_defaults/global_defaults.json
@@ -225,7 +225,7 @@
  "icon": "fa fa-cog", 
  "idx": 1, 
  "in_create": 1, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "is_transaction_doc": 0, 
  "issingle": 1, 
diff --git a/erpnext/setup/doctype/item_group/item_group.json b/erpnext/setup/doctype/item_group/item_group.json
index 6230706..29486b2 100644
--- a/erpnext/setup/doctype/item_group/item_group.json
+++ b/erpnext/setup/doctype/item_group/item_group.json
@@ -525,7 +525,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/print_heading/print_heading.json b/erpnext/setup/doctype/print_heading/print_heading.json
index d992fcb..dc07f0c 100644
--- a/erpnext/setup/doctype/print_heading/print_heading.json
+++ b/erpnext/setup/doctype/print_heading/print_heading.json
@@ -71,7 +71,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json
index b95a936..5d778ee 100644
--- a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json
+++ b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json
@@ -44,7 +44,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.json b/erpnext/setup/doctype/sales_partner/sales_partner.json
index 6c2d705..3c31c23 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.json
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.json
@@ -712,7 +712,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/sales_person/sales_person.json b/erpnext/setup/doctype/sales_person/sales_person.json
index 9f46501..b25f6a7 100644
--- a/erpnext/setup/doctype/sales_person/sales_person.json
+++ b/erpnext/setup/doctype/sales_person/sales_person.json
@@ -412,7 +412,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/target_detail/target_detail.json b/erpnext/setup/doctype/target_detail/target_detail.json
index 9bc8550..509733b 100644
--- a/erpnext/setup/doctype/target_detail/target_detail.json
+++ b/erpnext/setup/doctype/target_detail/target_detail.json
@@ -122,7 +122,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
index 40e54d8..5f25406 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
@@ -138,7 +138,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/territory/territory.json b/erpnext/setup/doctype/territory/territory.json
index b123d5e..81c2839 100644
--- a/erpnext/setup/doctype/territory/territory.json
+++ b/erpnext/setup/doctype/territory/territory.json
@@ -357,7 +357,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/uom/uom.json b/erpnext/setup/doctype/uom/uom.json
index e752d0f..e4322fe 100644
--- a/erpnext/setup/doctype/uom/uom.json
+++ b/erpnext/setup/doctype/uom/uom.json
@@ -77,7 +77,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/setup/doctype/website_item_group/website_item_group.json b/erpnext/setup/doctype/website_item_group/website_item_group.json
index 73084b5..8176e40 100644
--- a/erpnext/setup/doctype/website_item_group/website_item_group.json
+++ b/erpnext/setup/doctype/website_item_group/website_item_group.json
@@ -43,7 +43,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index fbf0ded..4f0bd0d 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -472,7 +472,8 @@
 							fields: ["attribute_value"],
 							limit_start: 0,
 							limit_page_length: 500,
-							parent: "Item"
+							parent: "Item",
+							order_by: "idx"
 						}
 					}).then((r) => {
 						if(r.message) {
diff --git a/erpnext/stock/doctype/item_attribute/item_attribute.json b/erpnext/stock/doctype/item_attribute/item_attribute.json
index 8c02928..4b23cf0 100644
--- a/erpnext/stock/doctype/item_attribute/item_attribute.json
+++ b/erpnext/stock/doctype/item_attribute/item_attribute.json
@@ -226,7 +226,7 @@
  "hide_toolbar": 0, 
  "icon": "fa fa-edit", 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/stock/doctype/item_attribute_value/item_attribute_value.json b/erpnext/stock/doctype/item_attribute_value/item_attribute_value.json
index 68edfc9..2807600 100644
--- a/erpnext/stock/doctype/item_attribute_value/item_attribute_value.json
+++ b/erpnext/stock/doctype/item_attribute_value/item_attribute_value.json
@@ -69,7 +69,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json
index 6147db9..f1e1fd3 100644
--- a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json
+++ b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json
@@ -70,7 +70,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item_reorder/item_reorder.json b/erpnext/stock/doctype/item_reorder/item_reorder.json
index 43eb98d..fb4c558 100644
--- a/erpnext/stock/doctype/item_reorder/item_reorder.json
+++ b/erpnext/stock/doctype/item_reorder/item_reorder.json
@@ -142,7 +142,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 1, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item_supplier/item_supplier.json b/erpnext/stock/doctype/item_supplier/item_supplier.json
index 163b427..6cff8e0 100644
--- a/erpnext/stock/doctype/item_supplier/item_supplier.json
+++ b/erpnext/stock/doctype/item_supplier/item_supplier.json
@@ -75,7 +75,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item_tax/item_tax.json b/erpnext/stock/doctype/item_tax/item_tax.json
index e9c9d62..6c1bd09 100644
--- a/erpnext/stock/doctype/item_tax/item_tax.json
+++ b/erpnext/stock/doctype/item_tax/item_tax.json
@@ -68,7 +68,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item_variant/item_variant.json b/erpnext/stock/doctype/item_variant/item_variant.json
index 9da66a2..93005c0 100644
--- a/erpnext/stock/doctype/item_variant/item_variant.json
+++ b/erpnext/stock/doctype/item_variant/item_variant.json
@@ -70,7 +70,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/item_website_specification/item_website_specification.json b/erpnext/stock/doctype/item_website_specification/item_website_specification.json
index 3c32adb..618c9f0 100644
--- a/erpnext/stock/doctype/item_website_specification/item_website_specification.json
+++ b/erpnext/stock/doctype/item_website_specification/item_website_specification.json
@@ -68,7 +68,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json b/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json
index d65da88..f49c147 100644
--- a/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json
+++ b/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json
@@ -168,7 +168,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/packed_item/packed_item.json b/erpnext/stock/doctype/packed_item/packed_item.json
index f9c1635..6c8b2b1 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.json
+++ b/erpnext/stock/doctype/packed_item/packed_item.json
@@ -665,7 +665,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json b/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json
index 009244c..1b22f13 100644
--- a/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json
+++ b/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json
@@ -430,7 +430,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/price_list_country/price_list_country.json b/erpnext/stock/doctype/price_list_country/price_list_country.json
index a7cef6f6..a0020c5 100644
--- a/erpnext/stock/doctype/price_list_country/price_list_country.json
+++ b/erpnext/stock/doctype/price_list_country/price_list_country.json
@@ -42,7 +42,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json
index a3b43e9..94aecfe 100644
--- a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json
+++ b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json
@@ -395,7 +395,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
index 8275c84..b6892f1 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
@@ -689,7 +689,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 1, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
diff --git a/erpnext/stock/doctype/uom_conversion_detail/uom_conversion_detail.json b/erpnext/stock/doctype/uom_conversion_detail/uom_conversion_detail.json
index a17cc2d..6f28651 100644
--- a/erpnext/stock/doctype/uom_conversion_detail/uom_conversion_detail.json
+++ b/erpnext/stock/doctype/uom_conversion_detail/uom_conversion_detail.json
@@ -69,7 +69,7 @@
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index b90ee32..9c47f98 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -144,19 +144,17 @@
 	if is_root:
 		parent = ""
 
-	fields = ['name as value', 'is_group as expandable']
-	filters = [
-		['docstatus', '<', '2'],
-		['parent_warehouse', '=', parent],
-		['company', 'in', (company, None,'')]
-	]
-
-	warehouses = frappe.get_list(doctype, fields=fields, filters=filters, order_by='name')
+	warehouses = frappe.db.sql("""select name as value,
+		is_group as expandable
+		from `tabWarehouse`
+		where docstatus < 2
+		and ifnull(`parent_warehouse`,'') = %s
+		and (`company` = %s or company is null or company = '')
+		order by name""", (parent, company), as_dict=1)
 
 	# return warehouses
 	for wh in warehouses:
 		wh["balance"] = get_stock_value_on(warehouse=wh.value)
-
 	return warehouses
 
 @frappe.whitelist()
diff --git a/erpnext/support/doctype/support_settings/support_settings.json b/erpnext/support/doctype/support_settings/support_settings.json
index 1ca03c7..7adfd4d 100644
--- a/erpnext/support/doctype/support_settings/support_settings.json
+++ b/erpnext/support/doctype/support_settings/support_settings.json
@@ -48,7 +48,7 @@
  "idx": 0, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
diff --git a/erpnext/utilities/doctype/rename_tool/rename_tool.json b/erpnext/utilities/doctype/rename_tool/rename_tool.json
index f9aac1c..617354d 100644
--- a/erpnext/utilities/doctype/rename_tool/rename_tool.json
+++ b/erpnext/utilities/doctype/rename_tool/rename_tool.json
@@ -78,7 +78,7 @@
  "icon": "fa fa-magic", 
  "idx": 1, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
diff --git a/erpnext/utilities/doctype/sms_log/sms_log.json b/erpnext/utilities/doctype/sms_log/sms_log.json
index ffd9a7f..d8f3146 100644
--- a/erpnext/utilities/doctype/sms_log/sms_log.json
+++ b/erpnext/utilities/doctype/sms_log/sms_log.json
@@ -256,7 +256,7 @@
  "icon": "fa fa-mobile-phone", 
  "idx": 1, 
  "in_create": 0, 
- "in_dialog": 0, 
+
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0,