Add Get Suppliers dialog (#10025)

* Add Get Suppliers dialog

* Commonize code, use depends_on

* Update request_for_quotation.js
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 1c7b5a8..558e072 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -54,6 +54,91 @@
 
 	},
 
+	get_suppliers_button: function (frm) {
+		var doc = frm.doc;
+		var dialog = new frappe.ui.Dialog({
+			title: __("Get Suppliers"),
+			fields: [
+				{	"fieldtype": "Select", "label": __("Get Suppliers By"),
+					"fieldname": "search_type",
+					"options": "Tag\nSupplier Type", "reqd": 1 },
+				{	"fieldtype": "Link", "label": __("Supplier Type"),
+					"fieldname": "supplier_type",
+					"options": "Supplier Type",	"reqd": 0,
+					"depends_on": "eval:doc.search_type == 'Supplier Type'"},
+				{	"fieldtype": "Data", "label": __("Tag"),
+					"fieldname": "tag",	"reqd": 0,
+					"depends_on": "eval:doc.search_type == 'Tag'" },
+				{	"fieldtype": "Button", "label": __("Add All Suppliers"),
+					"fieldname": "add_suppliers", "cssClass": "btn-primary"},
+			]
+		});
+
+		dialog.fields_dict.add_suppliers.$input.click(function() {
+			var args = dialog.get_values();
+			if(!args) return;
+			dialog.hide();
+
+			//Remove blanks
+			for (var j = 0; j < frm.doc.suppliers.length; j++) {
+				if(!frm.doc.suppliers[j].hasOwnProperty("supplier")) {
+					frm.get_field("suppliers").grid.grid_rows[j].remove();
+				}
+			}
+
+			 function load_suppliers(r) {
+				if(r.message) {
+					for (var i = 0; i < r.message.length; i++) {
+						var exists = false;
+						if (r.message[i].constructor === Array){
+							var supplier = r.message[i][0];
+						} else {
+							var supplier = r.message[i].name;
+						}
+
+						for (var j = 0; j < doc.suppliers.length;j++) {
+							if (supplier === doc.suppliers[j].supplier) {
+								exists = true;
+							}
+						}
+						if(!exists) {
+							var d = frm.add_child('suppliers');
+							d.supplier = supplier;
+							frm.script_manager.trigger("supplier", d.doctype, d.name);
+						}
+					}
+				}
+				frm.refresh_field("suppliers");
+			}
+
+			if (args.search_type === "Tag" && args.tag) {
+				return frappe.call({
+					type: "GET",
+					method: "frappe.desk.tags.get_tagged_docs",
+					args: {
+						"doctype": "Supplier",
+						"tag": args.tag
+					},
+					callback: load_suppliers
+				});
+			} else if (args.supplier_type) {
+				return frappe.call({
+					method: "frappe.client.get_list",
+					args: {
+						doctype: "Supplier",
+						order_by: "name",
+						fields: ["name"],
+						filters: [["Supplier", "supplier_type", "=", args.supplier_type]]
+
+					},
+					callback: load_suppliers
+				});
+			}
+		});
+		dialog.show();
+
+	},
+
 	make_suppplier_quotation: function(frm) {
 		var doc = frm.doc;
 		var dialog = new frappe.ui.Dialog({
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
index ac345d9..44068ce 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
@@ -25,7 +25,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_global_search": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Series", 
    "length": 0, 
@@ -59,7 +59,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_global_search": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Company", 
    "length": 0, 
@@ -156,7 +156,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_global_search": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Date", 
    "length": 0, 
@@ -242,6 +242,36 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "get_suppliers_button", 
+   "fieldtype": "Button", 
+   "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": "Get Suppliers", 
+   "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, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -406,7 +436,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_global_search": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Message for Supplier", 
    "length": 0, 
@@ -786,7 +816,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-06-13 14:29:13.171291", 
+ "modified": "2017-07-21 14:06:46.309322", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Request for Quotation",