[Fixes] Tax withholding category and Bank Guarantee (#14576)

* Fetch withheld percentage

* Set query for accounts on the basis of company

* Fix bank guarantee error on submit

* Remove errors caused by fields which are removed
diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
index 1a62c42..13ed5b6 100644
--- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
+++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
@@ -17,7 +17,7 @@
 			frappe.throw(_("Enter the Bank Guarantee Number before submittting."))
 		if not self.name_of_beneficiary:
 			frappe.throw(_("Enter the name of the Beneficiary before submittting."))
-		if not self.name_of_bank:
+		if not self.bank:
 			frappe.throw(_("Enter the name of the bank or lending institution before submittting."))
 
 @frappe.whitelist()
diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js
index da99a8d..b8d6c9a 100644
--- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js
+++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js
@@ -2,7 +2,16 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Tax Withholding Category', {
-	refresh: function(frm) {
-
+	setup: function(frm) {
+		frm.set_query("account", "accounts", function(doc, cdt, cdn) {
+			var child = locals[cdt][cdn];
+			if (child.company) {
+				return {
+					filters: {
+						'company': child.company
+					}
+				};
+			}
+		});
 	}
 });
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index bb7d55b..2cfca24 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -531,7 +531,7 @@
 		tax_withholding = frappe.get_doc("Tax Withholding Category", tax_withholding_category)
 
 	if tax_withholding.book_on_invoice and ref_doc.doctype=='Purchase Invoice' \
-		or tax_withholding.book_on_advance and ref_doc.doctype in ('Payment Entry', 'Journal Entry'):
+		or ref_doc.doctype in ('Payment Entry', 'Journal Entry'):
 
 		for account_detail in tax_withholding.accounts:
 			if ref_doc.company == account_detail.company:
diff --git a/erpnext/buying/doctype/party_tax_withholding_config/party_tax_withholding_config.json b/erpnext/buying/doctype/party_tax_withholding_config/party_tax_withholding_config.json
index 320485b..d2583e5 100644
--- a/erpnext/buying/doctype/party_tax_withholding_config/party_tax_withholding_config.json
+++ b/erpnext/buying/doctype/party_tax_withholding_config/party_tax_withholding_config.json
@@ -14,6 +14,7 @@
  "fields": [
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -46,6 +47,7 @@
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -77,10 +79,12 @@
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fetch_from": "tax_withholding_category.percent_of_tax_withheld", 
    "fieldname": "applicable_percent", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -108,6 +112,7 @@
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -148,7 +153,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2018-05-11 13:35:44.424855", 
+ "modified": "2018-06-18 22:38:38.638721", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Party Tax Withholding Config", 
@@ -162,5 +167,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "track_changes": 1, 
- "track_seen": 0
+ "track_seen": 0, 
+ "track_views": 0
 }
\ No newline at end of file
diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py
index 1a28f77..53299e0 100644
--- a/erpnext/regional/india/setup.py
+++ b/erpnext/regional/india/setup.py
@@ -284,8 +284,7 @@
 		{
 			'doctype': 'Tax Withholding Category', '__newname': 'TDS',
 			'percent_of_tax_withheld': 10,'threshold': 150000, 'book_on_invoice': 1,
-			'book_on_advance': 0, "withhold_cumulative_tax_amount": 0,
-			'accounts': accounts
+			'withhold_cumulative_tax_amount': 0, 'accounts': accounts
 		}
 	])