fix: Merge branch 'develop' into healthcare_refactor
diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py
index 569767e..c3e2f7d 100644
--- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py
+++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py
@@ -26,7 +26,7 @@
 		to_date = chart.to_date
 
 	timegrain = chart.time_interval
-	filters = frappe.parse_json(chart.filters_json)
+	filters = frappe.parse_json(filters) or frappe.parse_json(chart.filters_json)
 
 	account = filters.get("account")
 	company = filters.get("company")
diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json
index 64efc27..af252e6 100644
--- a/erpnext/accounts/doctype/account/account.json
+++ b/erpnext/accounts/doctype/account/account.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "allow_copy": 1,
  "allow_import": 1,
  "creation": "2013-01-30 12:49:46",
@@ -196,10 +197,13 @@
  ],
  "icon": "fa fa-money",
  "idx": 1,
- "modified": "2019-10-10 19:10:02.967554",
+ "is_tree": 1,
+ "links": [],
+ "modified": "2020-03-18 17:57:52.063233",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Account",
+ "nsm_parent_field": "parent_account",
  "owner": "Administrator",
  "permissions": [
   {
diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR04_with_account_number.json b/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR04_with_account_number.json
index adfa9f8..ff95c5a 100644
--- a/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR04_with_account_number.json
+++ b/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR04_with_account_number.json
@@ -406,11 +406,11 @@
                         "is_group": 1,
                         "Bewertungskorrektur zu Forderungen aus Lieferungen und Leistungen": {
                             "account_number": "9960"
-						},
-						"Debitoren": {
-							"is_group": 1,
-							"account_number": "10000"
-						},
+                        },
+                        "Debitoren": {
+                            "is_group": 1,
+                            "account_number": "10000"
+                        },
                         "Forderungen aus Lieferungen und Leistungen": {
                             "account_number": "1200",
                             "account_type": "Receivable"
@@ -663,16 +663,22 @@
                                 "account_number": "1400"
                             },
                             "Abziehbare Vorsteuer 7 %": {
-                                "account_number": "1401"
+                                "account_number": "1401",
+                                "account_type": "Tax",
+                                "tax_rate": 7.0
                             },
                             "Abziehbare Vorsteuer aus innergem. Erwerb": {
                                 "account_number": "1402"
                             },
                             "Abziehbare Vorsteuer aus innergem. Erwerb 19%": {
-                                "account_number": "1404"
+                                "account_number": "1404",
+                                "account_type": "Tax",
+                                "tax_rate": 19.0
                             },
                             "Abziehbare Vorsteuer 19 %": {
-                                "account_number": "1406"
+                                "account_number": "1406",
+                                "account_type": "Tax",
+                                "tax_rate": 19.0
                             },
                             "Abziehbare Vorsteuer nach \u00a7 13b UStG 19 %": {
                                 "account_number": "1407"
@@ -911,17 +917,31 @@
                 "is_group": 1,
                 "I - Gezeichnetes Kapital": {
                     "account_type": "Equity",
-                    "is_group": 1
+					"is_group": 1,
+					"Gezeichnetes Kapital": {
+						"account_type": "Equity",
+						"account_number": "2900"
+					},
+					"Ausstehende Einlagen auf das gezeichnete Kapital": {
+						"account_number": "2910",
+						"is_group": 1
+					}
                 },
                 "II - Kapitalr\u00fccklage": {
                     "account_type": "Equity",
-                    "is_group": 1
+					"is_group": 1,
+					"Kapitalr\u00fccklage": {
+						"account_number": "2920"
+					}
                 },
                 "III - Gewinnr\u00fccklagen": {
                     "account_type": "Equity",
                     "1 - gesetzliche R\u00fccklage": {
                         "account_type": "Equity",
-                        "is_group": 1
+						"is_group": 1,
+						"Gesetzliche R\u00fccklage": {
+							"account_number": "2930"
+						}
                     },
                     "2 - R\u00fccklage f. Anteile an einem herrschenden oder mehrheitlich beteiligten Unternehmen": {
                         "account_type": "Equity",
@@ -929,7 +949,10 @@
                     },
                     "3 - satzungsm\u00e4\u00dfige R\u00fccklagen": {
                         "account_type": "Equity",
-                        "is_group": 1
+						"is_group": 1,
+						"Satzungsm\u00e4\u00dfige R\u00fccklagen": {
+							"account_number": "2950"
+						}
                     },
                     "4 - andere Gewinnr\u00fccklagen": {
                         "account_type": "Equity",
@@ -963,7 +986,13 @@
                 },
                 "IV - Gewinnvortrag/Verlustvortrag": {
                     "account_type": "Equity",
-                    "is_group": 1
+                    "is_group": 1,
+					"Gewinnvortrag vor Verwendung": {
+						"account_number": "2970"
+					},
+					"Verlustvortrag vor Verwendung": {
+						"account_number": "2978"
+					}
                 },
                 "V - Jahres\u00fcberschu\u00df/Jahresfehlbetrag": {
                     "account_type": "Equity",
@@ -1197,15 +1226,15 @@
                     "is_group": 1,
                     "Bewertungskorrektur zu Verb. aus Lieferungen und Leistungen": {
                         "account_number": "9964"
-					},
-					"Kreditoren": {
-						"account_number": "70000",
-						"is_group": 1,
-						"Wareneingangs-­Verrechnungskonto" : {
-							"account_number": "70001",
-							"account_type": "Stock Received But Not Billed"
-						}
-					},
+                    },
+                    "Kreditoren": {
+                        "account_number": "70000",
+                        "is_group": 1,
+                        "Wareneingangs-­Verrechnungskonto" : {
+                            "account_number": "70001",
+                            "account_type": "Stock Received But Not Billed"
+                        }
+                    },
                     "Verb. aus Lieferungen und Leistungen": {
                         "account_number": "3300",
                         "account_type": "Payable"
@@ -1488,17 +1517,21 @@
                         },
                         "Umsatzsteuer 7 %": {
                             "account_number": "3801",
-                            "account_type": "Tax"
+                            "account_type": "Tax",
+                            "tax_rate": 7.0
                         },
                         "Umsatzsteuer aus innergem. Erwerb": {
                             "account_number": "3802"
                         },
                         "Umsatzsteuer aus innergem. Erwerb 19 %": {
-                            "account_number": "3804"
+                            "account_number": "3804",
+                            "account_type": "Tax",
+                            "tax_rate": 19.0
                         },
                         "Umsatzsteuer 19 %": {
                             "account_number": "3806",
-                            "account_type": "Tax"
+                            "account_type": "Tax",
+                            "tax_rate": 19.0
                         },
                         "Umsatzsteuer aus im Inland steuerpfl. EU-Lieferungen": {
                             "account_number": "3807"
@@ -1653,7 +1686,15 @@
             "Erl\u00f6se 7 % USt": {
                 "account_number": "4300",
                 "account_type": "Income Account"
-            },
+			},
+			"Erl\u00f6se 16 % USt": {
+				"account_number": "4340",
+                "account_type": "Income Account"
+			},
+			"Erl\u00f6se 19 % USt": {
+				"account_number": "4400",
+				"account_type": "Income Account"
+			},
             "Erl\u00f6se aus im Inland steuerpfl. EU-Lieferungen 7 % USt": {
                 "account_number": "4310"
             },
@@ -1681,19 +1722,6 @@
             "Erl\u00f6se aus im anderen EU-Land steuerbaren Leistungen, im Inland nicht steuerbare Ums\u00e4tze": {
                 "account_number": "4339"
             },
-            "Erl\u00f6se 16 % USt (Gruppe)": {
-                "is_group": 1,
-                "Erl\u00f6se 16 % USt": {
-                    "account_number": "4340"
-                }
-            },
-            "Erl\u00f6se 19 % USt (Gruppe)": {
-                "is_group": 1,
-                "Erl\u00f6se 19 % USt": {
-                    "account_number": "4400",
-                    "account_type": "Income Account"
-                }
-            },
             "Grundst\u00fccksertr\u00e4ge (Gruppe)": {
                 "is_group": 1,
                 "Grundst\u00fccksertr\u00e4ge": {
@@ -1752,14 +1780,12 @@
         "2 - Herstellungskosten der zur Erzielung der Umsatzerl\u00f6se erbrachten Leistungen": {
             "root_type": "Expense",
             "is_group": 1,
-            "Herstellungskosten (Gruppe)": {
-                "Herstellungskosten": {
-                    "account_number": "6990",
-                    "account_type": "Cost of Goods Sold"
-                },
-                "Herstellungskosten: Schwund": {
-                    "account_type": "Stock Adjustment"
-                }
+			"Herstellungskosten": {
+				"account_number": "6990",
+				"account_type": "Cost of Goods Sold"
+			},
+			"Herstellungskosten: Schwund": {
+				"account_type": "Stock Adjustment"
             },
             "Aufwendungen f. Roh-, Hilfs- und Betriebsstoffe und f. bezogene Waren": {
                 "account_number": "5000",
@@ -1809,10 +1835,10 @@
                     "Energiestoffe (Fertigung)": {
                         "account_number": "5190"
                     },
-                    "Energiestoffe (Fertigung)7% Vorsteuer": {
+                    "Energiestoffe (Fertigung) 7% Vorsteuer": {
                         "account_number": "5191"
                     },
-                    "Energiestoffe (Fertigung)19% Vorsteuer": {
+                    "Energiestoffe (Fertigung) 19% Vorsteuer": {
                         "account_number": "5192"
                     }
                 }
@@ -1935,49 +1961,49 @@
                 },
                 "Nachl\u00e4sse aus innergem. Erwerb 15 % Vorsteuer und 15 % Umsatzsteuer": {
                     "account_number": "5727"
-                },
-                "Erhaltene Skonti (Gruppe)": {
-                    "is_group": 1,
-                    "Erh. Skonti": {
-                        "account_number": "5730"
-                    },
-                    "Erh. Skonti 7 % Vorsteuer": {
-                        "account_number": "5731"
-                    },
-                    "Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe": {
-                        "account_number": "5733"
-                    },
-                    "Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe 7% Vorsteuer": {
-                        "account_number": "5734"
-                    },
-                    "Erh. Skonti 19 % Vorsteuer": {
-                        "account_number": "5736"
-                    },
-                    "Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe 19% Vorsteuer": {
-                        "account_number": "5738"
-                    },
-                    "Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe aus steuerpfl. innergem. Erwerb 19% Vorst. u. 19% Ust.": {
-                        "account_number": "5741"
-                    },
-                    "Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe aus steuerpfl. innergem. Erwerb 7% Vorst. u. 7% Ust.": {
-                        "account_number": "5743"
-                    },
-                    "Erh. Skonti aus steuerpflichtigem innergem. Erwerb": {
-                        "account_number": "5745"
-                    },
-                    "Erh. Skonti aus steuerpflichtigem innergem. Erwerb 7% Vorst. u. 7% Ust.": {
-                        "account_number": "5746"
-                    },
-                    "Erh. Skonti aus steuerpflichtigem innergem. Erwerb 19% Vorst. u. 19% Ust.": {
-                        "account_number": "5748"
-                    },
-                    "Erh. Skonti aus Erwerb Roh-,Hilfs-,Betriebsstoff letzter Abn.innerh.Dreiecksg. 19% Vorst. und 19% Ust.": {
-                        "account_number": "5792"
-                    },
-                    "Erh. Skonti aus Erwerb Waren als letzter Abnehmer innerh. Dreiecksgesch. 19% Vorst. u. 19% Ust.": {
-                        "account_number": "5793"
-                    }
-                }
+				}
+			},
+			"Erhaltene Skonti (Gruppe)": {
+				"is_group": 1,
+				"Erh. Skonti": {
+					"account_number": "5730"
+				},
+				"Erh. Skonti 7 % Vorsteuer": {
+					"account_number": "5731"
+				},
+				"Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe": {
+					"account_number": "5733"
+				},
+				"Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe 7% Vorsteuer": {
+					"account_number": "5734"
+				},
+				"Erh. Skonti 19 % Vorsteuer": {
+					"account_number": "5736"
+				},
+				"Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe 19% Vorsteuer": {
+					"account_number": "5738"
+				},
+				"Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe aus steuerpfl. innergem. Erwerb 19% Vorst. u. 19% Ust.": {
+					"account_number": "5741"
+				},
+				"Erh. Skonti aus Einkauf Roh-, Hilfs- und Betriebsstoffe aus steuerpfl. innergem. Erwerb 7% Vorst. u. 7% Ust.": {
+					"account_number": "5743"
+				},
+				"Erh. Skonti aus steuerpflichtigem innergem. Erwerb": {
+					"account_number": "5745"
+				},
+				"Erh. Skonti aus steuerpflichtigem innergem. Erwerb 7% Vorst. u. 7% Ust.": {
+					"account_number": "5746"
+				},
+				"Erh. Skonti aus steuerpflichtigem innergem. Erwerb 19% Vorst. u. 19% Ust.": {
+					"account_number": "5748"
+				},
+				"Erh. Skonti aus Erwerb Roh-,Hilfs-,Betriebsstoff letzter Abn.innerh.Dreiecksg. 19% Vorst. und 19% Ust.": {
+					"account_number": "5792"
+				},
+				"Erh. Skonti aus Erwerb Waren als letzter Abnehmer innerh. Dreiecksgesch. 19% Vorst. u. 19% Ust.": {
+					"account_number": "5793"
+				}
             },
             "Bezugsnebenkosten (Gruppe)": {
                 "is_group": 1,
@@ -2295,49 +2321,49 @@
         },
         "6 - sonstige betriebliche Ertr\u00e4ge": {
             "root_type": "Income",
-			"is_group": 1,
-			"Erhaltene Boni (Gruppe)": {
-				"is_group": 1,
-				"Erhaltene Boni 7 % Vorsteuer": {
-					"account_number": "5750"
-				},
-				"Erhaltene Boni aus Einkauf Roh-, Hilfs- und Betriebsstoffe": {
-					"account_number": "5753"
-				},
-				"Erhaltene Boni aus Einkauf Roh-, Hilfs- und Betriebsstoffe 7% Vorsteuer": {
-					"account_number": "5754"
-				},
-				"Erhaltene Boni aus Einkauf Roh-, Hilfs- und Betriebsstoffe 19% Vorsteuer": {
-					"account_number": "5755"
-				},
-				"Erhaltene Boni 19 % Vorsteuer": {
-					"account_number": "5760"
-				},
-				"Erhaltene Boni": {
-					"account_number": "5769"
-				}
-			},
-			"Erhaltene Rabatte (Gruppe)": {
-				"is_group": 1,
-				"Erhaltene Rabatte": {
-					"account_number": "5770"
-				},
-				"Erhaltene Rabatte 7 % Vorsteuer": {
-					"account_number": "5780"
-				},
-				"Erhaltene Rabatte aus Einkauf Roh-, Hilfs- und Betriebsstoffe": {
-					"account_number": "5783"
-				},
-				"Erhaltene Rabatte aus Einkauf Roh-, Hilfs- und Betriebsstoffe 7% Vorsteuer": {
-					"account_number": "5784"
-				},
-				"Erhaltene Rabatte aus Einkauf Roh-, Hilfs- und Betriebsstoffe 19% Vorsteuer": {
-					"account_number": "5785"
-				},
-				"Erhaltene Rabatte 19 % Vorsteuer": {
-					"account_number": "5790"
-				}
-			},
+            "is_group": 1,
+            "Erhaltene Boni (Gruppe)": {
+                "is_group": 1,
+                "Erhaltene Boni 7 % Vorsteuer": {
+                    "account_number": "5750"
+                },
+                "Erhaltene Boni aus Einkauf Roh-, Hilfs- und Betriebsstoffe": {
+                    "account_number": "5753"
+                },
+                "Erhaltene Boni aus Einkauf Roh-, Hilfs- und Betriebsstoffe 7% Vorsteuer": {
+                    "account_number": "5754"
+                },
+                "Erhaltene Boni aus Einkauf Roh-, Hilfs- und Betriebsstoffe 19% Vorsteuer": {
+                    "account_number": "5755"
+                },
+                "Erhaltene Boni 19 % Vorsteuer": {
+                    "account_number": "5760"
+                },
+                "Erhaltene Boni": {
+                    "account_number": "5769"
+                }
+            },
+            "Erhaltene Rabatte (Gruppe)": {
+                "is_group": 1,
+                "Erhaltene Rabatte": {
+                    "account_number": "5770"
+                },
+                "Erhaltene Rabatte 7 % Vorsteuer": {
+                    "account_number": "5780"
+                },
+                "Erhaltene Rabatte aus Einkauf Roh-, Hilfs- und Betriebsstoffe": {
+                    "account_number": "5783"
+                },
+                "Erhaltene Rabatte aus Einkauf Roh-, Hilfs- und Betriebsstoffe 7% Vorsteuer": {
+                    "account_number": "5784"
+                },
+                "Erhaltene Rabatte aus Einkauf Roh-, Hilfs- und Betriebsstoffe 19% Vorsteuer": {
+                    "account_number": "5785"
+                },
+                "Erhaltene Rabatte 19 % Vorsteuer": {
+                    "account_number": "5790"
+                }
+            },
             "Andere aktivierte Eigenleistungen": {
                 "account_number": "4820"
             },
@@ -2660,8 +2686,8 @@
         },
         "7 - sonstige betriebliche Aufwendungen": {
             "root_type": "Expense",
-			"is_group": 1,
-			"Erl\u00f6sschm\u00e4lerungen (Gruppe)": {
+            "is_group": 1,
+            "Erl\u00f6sschm\u00e4lerungen (Gruppe)": {
                 "is_group": 1,
                 "Erl\u00f6sschm\u00e4lerungen": {
                     "account_number": "4700"
@@ -2744,7 +2770,7 @@
                 "Gew\u00e4hrte Rabatte 19 % USt": {
                     "account_number": "4790"
                 }
-			},
+            },
             "Sonstige betriebliche Aufwendungen": {
                 "account_number": "6300"
             },
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
index a36f421..3c12f85 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
@@ -48,12 +48,6 @@
 		frm.set_value('label', frm.doc.document_type);
 		frm.set_value('fieldname', frappe.model.scrub(frm.doc.document_type));
 
-		if (frm.is_new()){
-			let row = frappe.model.add_child(frm.doc, "Accounting Dimension Detail", "dimension_defaults");
-			row.reference_document = frm.doc.document_type;
-			frm.refresh_fields("dimension_defaults");
-		}
-
 		frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => {
 			if (r && r.document_type) {
 				frm.set_df_property('document_type', 'description', "Document type is already set as dimension");
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json
index cf6dc7a..cf55d55 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "autoname": "field:label",
  "creation": "2019-05-04 18:13:37.002352",
  "doctype": "DocType",
@@ -46,7 +47,8 @@
    "options": "Accounting Dimension Detail"
   }
  ],
- "modified": "2019-07-17 16:49:31.134385",
+ "links": [],
+ "modified": "2020-03-22 20:34:39.805728",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Accounting Dimension",
@@ -63,9 +65,20 @@
    "role": "System Manager",
    "share": 1,
    "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Accounts Manager",
+   "share": 1,
+   "write": 1
   }
  ],
- "quick_entry": 1,
  "sort_field": "modified",
  "sort_order": "ASC",
  "track_changes": 1
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
index 522ed4f..462d967 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
@@ -172,7 +172,7 @@
 	return doclist
 
 def get_accounting_dimensions(as_list=True):
-	accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "disabled"])
+	accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "disabled", "document_type"])
 
 	if as_list:
 		return [d.fieldname for d in accounting_dimensions]
@@ -186,6 +186,18 @@
 
 	return dimensions
 
+def get_dimension_with_children(doctype, dimension):
+
+	if isinstance(dimension, list):
+		dimension = dimension[0]
+
+	all_dimensions = []
+	lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
+	children = frappe.get_all(doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
+	all_dimensions += [c.name for c in children]
+
+	return all_dimensions
+
 @frappe.whitelist()
 def get_dimension_filters():
 	dimension_filters = frappe.db.sql("""
diff --git a/erpnext/accounts/doctype/accounts_settings/regional/united_states.js b/erpnext/accounts/doctype/accounts_settings/regional/united_states.js
new file mode 100644
index 0000000..d47d6e5
--- /dev/null
+++ b/erpnext/accounts/doctype/accounts_settings/regional/united_states.js
@@ -0,0 +1,8 @@
+
+frappe.ui.form.on('Accounts Settings', {
+	refresh: function(frm) {
+		frm.set_df_property("acc_frozen_upto", "label", "Books Closed Through");
+		frm.set_df_property("frozen_accounts_modifier", "label", "Role Allowed to Close Books & Make Changes to Closed Periods");
+		frm.set_df_property("credit_controller", "label", "Credit Manager");
+	}
+});
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
index 9aa2ee2..f28a074 100644
--- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
+++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
@@ -6,6 +6,7 @@
 import frappe, json
 from frappe.model.document import Document
 from frappe import _
+from frappe.desk.search import sanitize_searchfield
 
 class BankGuarantee(Document):
 	def validate(self):
@@ -22,5 +23,8 @@
 
 @frappe.whitelist()
 def get_vouchar_detials(column_list, doctype, docname):
+	column_list = json.loads(column_list)
+	for col in column_list:
+		sanitize_searchfield(col) 
 	return frappe.db.sql(''' select {columns} from `tab{doctype}` where name=%s'''
 		.format(columns=", ".join(json.loads(column_list)), doctype=doctype), docname, as_dict=1)[0]
diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js
index 3d0fc0a..846408f 100644
--- a/erpnext/accounts/doctype/c_form/c_form.js
+++ b/erpnext/accounts/doctype/c_form/c_form.js
@@ -32,10 +32,12 @@
 	invoice_no(frm, cdt, cdn) {
 		let d = frappe.get_doc(cdt, cdn);
 
-		frm.call('get_invoice_details', {
-			invoice_no: d.invoice_no
-		}).then(r => {
-			frappe.model.set_value(cdt, cdn, r.message);
-		});
+		if (d.invoice_no) {
+			frm.call('get_invoice_details', {
+				invoice_no: d.invoice_no
+			}).then(r => {
+				frappe.model.set_value(cdt, cdn, r.message);
+			});
+		}
 	}
 });
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.json b/erpnext/accounts/doctype/cost_center/cost_center.json
index 976f05a..99b89d1 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.json
+++ b/erpnext/accounts/doctype/cost_center/cost_center.json
@@ -124,11 +124,13 @@
  ],
  "icon": "fa fa-money",
  "idx": 1,
+ "is_tree": 1,
  "links": [],
- "modified": "2020-01-28 13:50:23.430434",
+ "modified": "2020-03-18 17:59:04.321637",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Cost Center",
+ "nsm_parent_field": "parent_cost_center",
  "owner": "Administrator",
  "permissions": [
   {
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index f9e4fd7..14d0531 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -233,35 +233,14 @@
 			frappe.throw(_("Outstanding for {0} cannot be less than zero ({1})").format(against_voucher, fmt_money(bal)))
 
 	if against_voucher_type in ["Sales Invoice", "Purchase Invoice", "Fees"]:
-		update_outstanding_amt_in_ref(against_voucher, against_voucher_type, bal)
-
-def update_outstanding_amt_in_ref(against_voucher, against_voucher_type, bal):
-	data = []
-	# Update outstanding amt on against voucher
-	if against_voucher_type == "Fees":
 		ref_doc = frappe.get_doc(against_voucher_type, against_voucher)
-		ref_doc.db_set('outstanding_amount', bal)
-		ref_doc.set_status(update=True)
-		return
-	elif against_voucher_type == "Purchase Invoice":
-		from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import get_status
-		data = frappe.db.get_value(against_voucher_type, against_voucher, 
-			["name as purchase_invoice", "outstanding_amount", 
-			"is_return", "due_date", "docstatus"])
-	elif against_voucher_type == "Sales Invoice":
-		from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_status
-		data = frappe.db.get_value(against_voucher_type, against_voucher, 
-			["name as sales_invoice", "outstanding_amount", "is_discounted", 
-			"is_return", "due_date", "docstatus"])
 
-	precision = frappe.get_precision(against_voucher_type, "outstanding_amount")
-	data = list(data)
-	data.append(precision)
-	status = get_status(data)
-	frappe.db.set_value(against_voucher_type, against_voucher, {
-		'outstanding_amount': bal,
-		'status': status
-	})
+		# Didn't use db_set for optimisation purpose
+		ref_doc.outstanding_amount = bal
+		frappe.db.set_value(against_voucher_type, against_voucher, 'outstanding_amount', bal)
+
+		ref_doc.set_status(update=True)
+
 
 def validate_frozen_account(account, adv_adj=None):
 	frozen_account = frappe.db.get_value("Account", account, "freeze_account")
diff --git a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py
index 01ddd29..b4a547b 100644
--- a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py
@@ -38,6 +38,7 @@
 			filters={"voucher_type": "Journal Entry", "voucher_no": je.name},
 			order_by="creation"
 		)
+
 		self.assertTrue(all(entry.to_rename == 1 for entry in gl_entries))
 		old_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0]
 
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 2cbd40b..eb3017a 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -454,8 +454,10 @@
 	def set_print_format_fields(self):
 		bank_amount = party_amount = total_amount = 0.0
 		currency = bank_account_currency = party_account_currency = pay_to_recd_from= None
+		party_type = None
 		for d in self.get('accounts'):
 			if d.party_type in ['Customer', 'Supplier'] and d.party:
+				party_type = d.party_type
 				if not pay_to_recd_from:
 					pay_to_recd_from = d.party
 
@@ -467,9 +469,9 @@
 				bank_amount += (d.debit_in_account_currency or d.credit_in_account_currency)
 				bank_account_currency = d.account_currency
 
-		if pay_to_recd_from:
-			self.pay_to_recd_from = frappe.db.get_value(d.party_type, pay_to_recd_from,
-				"customer_name" if d.party_type=="Customer" else "supplier_name")
+		if party_type and pay_to_recd_from:
+			self.pay_to_recd_from = frappe.db.get_value(party_type, pay_to_recd_from,
+				"customer_name" if party_type=="Customer" else "supplier_name")
 			if bank_amount:
 				total_amount = bank_amount
 				currency = bank_account_currency
diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
index 5303743..a25e0e3 100644
--- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
@@ -161,15 +161,15 @@
 		pe.insert()
 		pe.submit()
 
-		outstanding_amount = flt(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"))
-		self.assertEqual(outstanding_amount, 0)
-		self.assertEqual(si.status, 'Paid')
+		outstanding_amount, status = frappe.db.get_value("Sales Invoice", si.name, ["outstanding_amount", "status"])
+		self.assertEqual(flt(outstanding_amount), 0)
+		self.assertEqual(status, 'Paid')
 
 		pe.cancel()
 
-		outstanding_amount = flt(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"))
-		self.assertEqual(outstanding_amount, 100)
-		self.assertEqual(si.status, 'Unpaid')
+		outstanding_amount, status = frappe.db.get_value("Sales Invoice", si.name, ["outstanding_amount", "status"])
+		self.assertEqual(flt(outstanding_amount), 100)
+		self.assertEqual(status, 'Unpaid')
 
 	def test_payment_against_purchase_invoice_to_check_status(self):
 		pi = make_purchase_invoice(supplier="_Test Supplier USD", debit_to="_Test Payable USD - _TC",
@@ -182,15 +182,15 @@
 		pe.insert()
 		pe.submit()
 
-		outstanding_amount = flt(frappe.db.get_value("Purchase Invoice", pi.name, "outstanding_amount"))
-		self.assertEqual(outstanding_amount, 0)
-		self.assertEqual(pi.status, 'Paid')
+		outstanding_amount, status = frappe.db.get_value("Purchase Invoice", pi.name, ["outstanding_amount", "status"])
+		self.assertEqual(flt(outstanding_amount), 0)
+		self.assertEqual(status, 'Paid')
 
 		pe.cancel()
 
-		outstanding_amount = flt(frappe.db.get_value("Purchase Invoice", pi.name, "outstanding_amount"))
-		self.assertEqual(outstanding_amount, 100)
-		self.assertEqual(pi.status, 'Unpaid')
+		outstanding_amount, status = frappe.db.get_value("Purchase Invoice", pi.name, ["outstanding_amount", "status"])
+		self.assertEqual(flt(outstanding_amount), 250)
+		self.assertEqual(status, 'Unpaid')
 
 	def test_payment_entry_against_ec(self):
 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index cc992ce..87d40fc 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -125,27 +125,6 @@
 			else:
 				self.remarks = _("No Remarks")
 
-	def set_status(self, update=False, status=None, update_modified=True):
-		if self.is_new():
-			if self.get('amended_from'):
-				self.status = 'Draft'
-			return
-
-		if not status:
-			precision = self.precision("outstanding_amount")
-			args = [
-				self.name,
-				self.outstanding_amount,
-				self.is_return,
-				self.due_date,
-				self.docstatus,
-				precision
-			]
-			self.status = get_status(args)
-
-		if update:
-			self.db_set('status', self.status, update_modified = update_modified)
-
 	def set_missing_values(self, for_validate=False):
 		if not self.credit_to:
 			self.credit_to = get_party_account("Supplier", self.supplier, self.company)
@@ -1028,34 +1007,6 @@
 		# calculate totals again after applying TDS
 		self.calculate_taxes_and_totals()
 
-def get_status(*args):
-	purchase_invoice, outstanding_amount, is_return, due_date, docstatus, precision = args[0]
-
-	outstanding_amount = flt(outstanding_amount, precision)
-	due_date = getdate(due_date)
-	now_date = getdate()
-
-	if docstatus == 2:
-		status = "Cancelled"
-	elif docstatus == 1:
-		if outstanding_amount > 0 and due_date < now_date:
-			status = "Overdue"
-		elif outstanding_amount > 0 and due_date >= now_date:
-			status = "Unpaid"
-		#Check if outstanding amount is 0 due to debit note issued against invoice
-		elif outstanding_amount <= 0 and is_return == 0 and frappe.db.get_value('Purchase Invoice', {'is_return': 1, 'return_against': purchase_invoice, 'docstatus': 1}):
-			status = "Debit Note Issued"
-		elif is_return == 1:
-			status = "Return"
-		elif outstanding_amount <=0:
-			status = "Paid"
-		else:
-			status = "Submitted"
-	else:
-		status = "Draft"
-
-	return status
-
 def get_list_context(context=None):
 	from erpnext.controllers.website_list_for_contact import get_list_context
 	list_context = get_list_context(context)
@@ -1116,3 +1067,6 @@
 def make_inter_company_sales_invoice(source_name, target_doc=None):
 	from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_transaction
 	return make_inter_company_transaction("Purchase Invoice", source_name, target_doc)
+
+def on_doctype_update():
+	frappe.db.add_index("Purchase Invoice", ["supplier", "is_return", "return_against"])
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index 4a7322d..ef90b94 100644
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -777,7 +777,7 @@
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2020-03-05 14:20:17.297284",
+ "modified": "2020-03-11 14:20:17.297284",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index c0e1285..c49ac29 100755
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -423,7 +423,10 @@
 				name_list.append(name)
 
 	email_queue = make_email_queue(email_queue_list)
-	pos_profile = json.loads(pos_profile)
+
+	if isinstance(pos_profile, string_types):
+		pos_profile = json.loads(pos_profile)
+
 	customers = get_customers_list(pos_profile)
 	return {
 		'invoice': name_list,
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 7f7938d..ba1ceff 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1223,18 +1223,38 @@
 				self.status = 'Draft'
 			return
 
+		precision = self.precision("outstanding_amount")
+		outstanding_amount = flt(self.outstanding_amount, precision)
+		due_date = getdate(self.due_date)
+		nowdate = getdate()
+
+		discounting_status = None
+		if self.is_discounted:
+			discountng_status = get_discounting_status(self.name)
+
 		if not status:
-			precision = self.precision("outstanding_amount")
-			args = [
-				self.name,
-				self.outstanding_amount,
-				self.is_discounted,
-				self.is_return,
-				self.due_date,
-				self.docstatus,
-				precision,
-			]
-			self.status = get_status(args)
+			if self.docstatus == 2:
+				status = "Cancelled"
+			elif self.docstatus == 1:
+				if outstanding_amount > 0 and due_date < nowdate and self.is_discounted and discountng_status=='Disbursed':
+					self.status = "Overdue and Discounted"
+				elif outstanding_amount > 0 and due_date < nowdate:
+					self.status = "Overdue"
+				elif outstanding_amount > 0 and due_date >= nowdate and self.is_discounted and discountng_status=='Disbursed':
+					self.status = "Unpaid and Discounted"
+				elif outstanding_amount > 0 and due_date >= nowdate:
+					self.status = "Unpaid"
+				#Check if outstanding amount is 0 due to credit note issued against invoice
+				elif outstanding_amount <= 0 and self.is_return == 0 and frappe.db.get_value('Sales Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1}):
+					self.status = "Credit Note Issued"
+				elif self.is_return == 1:
+					self.status = "Return"
+				elif outstanding_amount<=0:
+					self.status = "Paid"
+				else:
+					self.status = "Submitted"
+			else:
+				self.status = "Draft"
 
 		if update:
 			self.db_set('status', self.status, update_modified = update_modified)
@@ -1259,42 +1279,6 @@
 
 	return status
 
-def get_status(*args):
-	sales_invoice, outstanding_amount, is_discounted, is_return, due_date, docstatus, precision = args[0]
-
-	discounting_status = None
-	if is_discounted:
-		discounting_status = get_discounting_status(sales_invoice)
-
-	outstanding_amount = flt(outstanding_amount, precision)
-	due_date = getdate(due_date)
-	now_date = getdate()
-
-	if docstatus == 2:
-		status = "Cancelled"
-	elif docstatus == 1:
-		if outstanding_amount > 0 and due_date < now_date and is_discounted and discounting_status=='Disbursed':
-			status = "Overdue and Discounted"
-		elif outstanding_amount > 0 and due_date < now_date:
-			status = "Overdue"
-		elif outstanding_amount > 0 and due_date >= now_date and is_discounted and discounting_status=='Disbursed':
-			status = "Unpaid and Discounted"
-		elif outstanding_amount > 0 and due_date >= now_date:
-			status = "Unpaid"
-		#Check if outstanding amount is 0 due to credit note issued against invoice
-		elif outstanding_amount <= 0 and is_return == 0 and frappe.db.get_value('Sales Invoice', {'is_return': 1, 'return_against': sales_invoice, 'docstatus': 1}):
-			status = "Credit Note Issued"
-		elif is_return == 1:
-			status = "Return"
-		elif outstanding_amount <=0:
-			status = "Paid"
-		else:
-			status = "Submitted"
-	else:
-		status = "Draft"
-
-	return status
-
 def validate_inter_company_party(doctype, party, company, inter_company_reference):
 	if not party:
 		return
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index e48e6c9..3d5ce8a 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -786,7 +786,7 @@
 	def test_make_pos_invoice(self):
 		from erpnext.accounts.doctype.sales_invoice.pos import make_invoice
 
-		make_pos_profile()
+		pos_profile = make_pos_profile()
 		pr = make_purchase_receipt(company= "_Test Company with perpetual inventory",supplier_warehouse= "Work In Progress - TCP1", item_code= "_Test FG Item",warehouse= "Stores - TCP1",cost_center= "Main - TCP1")
 		pos = create_sales_invoice(company= "_Test Company with perpetual inventory", debit_to="Debtors - TCP1", item_code= "_Test FG Item", warehouse="Stores - TCP1", income_account = "Sales - TCP1", expense_account = "Cost of Goods Sold - TCP1", cost_center = "Main - TCP1", do_not_save=True)
 
@@ -802,7 +802,7 @@
 			pos.append("taxes", tax)
 
 		invoice_data = [{'09052016142': pos}]
-		si = make_invoice(invoice_data).get('invoice')
+		si = make_invoice(pos_profile, invoice_data).get('invoice')
 		self.assertEqual(si[0], '09052016142')
 
 		sales_invoice = frappe.get_all('Sales Invoice', fields =["*"], filters = {'offline_pos_name': '09052016142', 'docstatus': 1})
@@ -820,7 +820,7 @@
 		if allow_negative_stock:
 			frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 0)
 
-		make_pos_profile()
+		pos_profile = make_pos_profile()
 		timestamp = cint(time.time())
 
 		item = make_item("_Test POS Item")
@@ -834,7 +834,7 @@
 							{'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 330}]
 
 		invoice_data = [{timestamp: pos}]
-		si = make_invoice(invoice_data).get('invoice')
+		si = make_invoice(pos_profile, invoice_data).get('invoice')
 		self.assertEqual(si[0], timestamp)
 
 		sales_invoice = frappe.get_all('Sales Invoice', fields =["*"], filters = {'offline_pos_name': timestamp})
@@ -843,7 +843,7 @@
 		timestamp = cint(time.time())
 		pos["offline_pos_name"] = timestamp
 		invoice_data = [{timestamp: pos}]
-		si1 = make_invoice(invoice_data).get('invoice')
+		si1 = make_invoice(pos_profile, invoice_data).get('invoice')
 		self.assertEqual(si1[0], timestamp)
 
 		sales_invoice1 = frappe.get_all('Sales Invoice', fields =["*"], filters = {'offline_pos_name': timestamp})
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 6d53530..5ba455c 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -136,12 +136,11 @@
 
 
 def make_entry(args, adv_adj, update_outstanding, from_repost=False):
-	args.update({"doctype": "GL Entry"})
-	gle = frappe.get_doc(args)
+	gle = frappe.new_doc("GL Entry")
+	gle.update(args)
 	gle.flags.ignore_permissions = 1
 	gle.flags.from_repost = from_repost
 	gle.validate()
-	gle.flags.ignore_permissions = True
 	gle.db_insert()
 	gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost)
 	gle.flags.ignore_validate = True
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index 0438f6d..240b0d8 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -7,7 +7,7 @@
 from frappe.utils import getdate, nowdate, flt, cint, formatdate, cstr, now, time_diff_in_seconds
 from collections import OrderedDict
 from erpnext.accounts.utils import get_currency_precision
-from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions, get_dimension_with_children
 
 #  This report gives a summary of all Outstanding Invoices considering the following
 
@@ -603,7 +603,6 @@
 			self.add_supplier_filters(conditions, values)
 
 		self.add_accounting_dimensions_filters(conditions, values)
-
 		return " and ".join(conditions), values
 
 	def get_order_by_condition(self):
@@ -666,13 +665,16 @@
 					doctype=doctype, lft=lft, rgt=rgt, key=key)
 
 	def add_accounting_dimensions_filters(self, conditions, values):
-		accounting_dimensions = get_accounting_dimensions()
+		accounting_dimensions = get_accounting_dimensions(as_list=False)
 
 		if accounting_dimensions:
 			for dimension in accounting_dimensions:
-				if self.filters.get(dimension):
-					conditions.append("{0} = %s".format(dimension))
-					values.append(self.filters.get(dimension))
+				if self.filters.get(dimension.fieldname):
+					if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
+						self.filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
+							self.filters.get(dimension.fieldname))
+					conditions.append("{0} in %s".format(dimension.fieldname))
+					values.append(tuple(self.filters.get(dimension.fieldname)))
 
 	def get_gle_balance(self, gle):
 		# get the balance of the GL (debit - credit) or reverse balance based on report type
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 35915d0..080a7c9 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -16,7 +16,7 @@
 from frappe.utils import (flt, getdate, get_first_day, add_months, add_days, formatdate, cstr)
 
 from six import itervalues
-from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions, get_dimension_with_children
 
 def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_values=False,
 	company=None, reset_period_on_fy_change=True):
@@ -389,7 +389,7 @@
 def get_additional_conditions(from_date, ignore_closing_entries, filters):
 	additional_conditions = []
 
-	accounting_dimensions = get_accounting_dimensions()
+	accounting_dimensions = get_accounting_dimensions(as_list=False)
 
 	if ignore_closing_entries:
 		additional_conditions.append("ifnull(voucher_type, '')!='Period Closing Voucher'")
@@ -412,11 +412,14 @@
 			additional_conditions.append("(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)")
 		else:
 			additional_conditions.append("(finance_book in (%(finance_book)s, '') OR finance_book IS NULL)")
-		
+
 	if accounting_dimensions:
 		for dimension in accounting_dimensions:
-			if filters.get(dimension):
-				additional_conditions.append("{0} in (%({0})s)".format(dimension))
+			if filters.get(dimension.fieldname):
+				if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
+					filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
+						filters.get(dimension.fieldname))
+				additional_conditions.append("{0} in %({0})s".format(dimension.fieldname))
 
 	return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
 
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.html b/erpnext/accounts/report/general_ledger/general_ledger.html
index 40469ae..9a2205a 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.html
+++ b/erpnext/accounts/report/general_ledger/general_ledger.html
@@ -2,7 +2,7 @@
 <h4 class="text-center">
 	{% if (filters.party_name) { %}
 		{%= filters.party_name %}
-	{% } else if (filters.party && filters.show_name) { %}
+	{% } else if (filters.party) { %}
 		{%= filters.party %}
 	{% } else if (filters.account) { %}
 		{%= filters.account %}
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 8bea365..8750c23 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -10,7 +10,7 @@
 from erpnext.accounts.utils import get_account_currency
 from erpnext.accounts.report.financial_statements import get_cost_centers_with_children
 from six import iteritems
-from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions, get_dimension_with_children
 from collections import OrderedDict
 
 def execute(filters=None):
@@ -194,12 +194,15 @@
 	if match_conditions:
 		conditions.append(match_conditions)
 
-	accounting_dimensions = get_accounting_dimensions()
+	accounting_dimensions = get_accounting_dimensions(as_list=False)
 
 	if accounting_dimensions:
 		for dimension in accounting_dimensions:
-			if filters.get(dimension):
-				conditions.append("{0} in (%({0})s)".format(dimension))
+			if filters.get(dimension.fieldname):
+				if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
+					filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
+						filters.get(dimension.fieldname))
+				conditions.append("{0} in %({0})s".format(dimension.fieldname))
 
 	return "and {}".format(" and ".join(conditions)) if conditions else ""
 
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 11f4e0d..127f313 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -201,7 +201,8 @@
 		{
 			'label': _('Mode Of Payment'),
 			'fieldname': 'mode_of_payment',
-			'fieldtype': 'Data',
+			'fieldtype': 'Link',
+			'options': 'Mode of Payment',
 			'width': 120
 		},
 		{
@@ -309,6 +310,8 @@
 
 	if additional_query_columns:
 		additional_query_columns = ', ' + ', '.join(additional_query_columns)
+	else:
+		additional_query_columns = ''
 
 	return frappe.db.sql("""
 		select
@@ -320,7 +323,7 @@
 			`tabPurchase Invoice Item`.`purchase_receipt`, `tabPurchase Invoice Item`.`po_detail`,
 			`tabPurchase Invoice Item`.`expense_account`, `tabPurchase Invoice Item`.`stock_qty`,
 			`tabPurchase Invoice Item`.`stock_uom`, `tabPurchase Invoice Item`.`base_net_amount`,
-			`tabPurchase Invoice`.supplier_name, `tabPurchase Invoice`.mode_of_payment {0}
+			`tabPurchase Invoice`.`supplier_name`, `tabPurchase Invoice`.`mode_of_payment` {0}
 		from `tabPurchase Invoice`, `tabPurchase Invoice Item`
 		where `tabPurchase Invoice`.name = `tabPurchase Invoice Item`.`parent` and
 		`tabPurchase Invoice`.docstatus = 1 %s
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index 786e04d..0c8957a 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -373,6 +373,8 @@
 
 	if additional_query_columns:
 		additional_query_columns = ', ' + ', '.join(additional_query_columns)
+	else:
+		additional_query_columns = ''
 
 	return frappe.db.sql("""
 		select
diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py
index 2be90bc..9864e40 100644
--- a/erpnext/accounts/report/sales_register/sales_register.py
+++ b/erpnext/accounts/report/sales_register/sales_register.py
@@ -6,7 +6,7 @@
 from frappe.utils import flt
 from frappe import msgprint, _
 from frappe.model.meta import get_field_precision
-from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions, get_dimension_with_children
 
 def execute(filters=None):
 	return _execute(filters)
@@ -341,14 +341,18 @@
 			 where parent=`tabSales Invoice`.name
 			 	and ifnull(`tabSales Invoice Item`.item_group, '') = %(item_group)s)"""
 
-	accounting_dimensions = get_accounting_dimensions()
+	accounting_dimensions = get_accounting_dimensions(as_list=False)
 
 	if accounting_dimensions:
 		for dimension in accounting_dimensions:
-			if filters.get(dimension):
+			if filters.get(dimension.fieldname):
+				if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
+					filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
+						filters.get(dimension.fieldname))
+
 				conditions += """ and exists(select name from `tabSales Invoice Item`
 					where parent=`tabSales Invoice`.name
-						and ifnull(`tabSales Invoice Item`.{0}, '') = %({0})s)""".format(dimension)
+						and ifnull(`tabSales Invoice Item`.{0}, '') in %({0})s)""".format(dimension.fieldname)
 
 
 	return conditions
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py
index 69285cc..5fe6b41 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.py
+++ b/erpnext/accounts/report/trial_balance/trial_balance.py
@@ -7,7 +7,7 @@
 from frappe.utils import flt, getdate, formatdate, cstr
 from erpnext.accounts.report.financial_statements \
 	import filter_accounts, set_gl_entries_by_account, filter_out_zero_value_rows
-from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions, get_dimension_with_children
 
 value_fields = ("opening_debit", "opening_credit", "debit", "credit", "closing_debit", "closing_credit")
 
@@ -109,7 +109,7 @@
 
 		additional_conditions += fb_conditions
 
-	accounting_dimensions = get_accounting_dimensions()
+	accounting_dimensions = get_accounting_dimensions(as_list=False)
 
 	query_filters = {
 		"company": filters.company,
@@ -122,11 +122,14 @@
 
 	if accounting_dimensions:
 		for dimension in accounting_dimensions:
-			if filters.get(dimension):
-				additional_conditions += """ and {0} in (%({0})s) """.format(dimension)
+			if filters.get(dimension.fieldname):
+				if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
+					filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
+						filters.get(dimension.fieldname))
+				additional_conditions += "and {0} in %({0})s".format(dimension.fieldname)
 
 				query_filters.update({
-					dimension: filters.get(dimension)
+					dimension.fieldname: filters.get(dimension.fieldname)
 				})
 
 	gle = frappe.db.sql("""