[fixes] filter on supplier list for DropShip, checking closed status
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index dee2b7b..60fdc1a 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -52,7 +52,7 @@
 		self.validate_proj_cust()
 		self.validate_with_previous_doc()
 		self.validate_uom_is_integer("stock_uom", "qty")
-		self.check_stop_sales_order("sales_order")
+		self.check_stop_or_close_sales_order("sales_order")
 		self.validate_debit_to_acc()
 		self.validate_fixed_asset_account()
 		self.clear_unallocated_advances("Sales Invoice Advance", "advances")
@@ -117,7 +117,7 @@
 		if cint(self.update_stock) == 1:
 			self.update_stock_ledger()
 
-		self.check_stop_sales_order("sales_order")
+		self.check_stop_or_close_sales_order("sales_order")
 
 		from erpnext.accounts.utils import remove_against_link_from_jv
 		remove_against_link_from_jv(self.doctype, self.name)
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index b087b8a..7135baf 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -219,12 +219,14 @@
 		so_warehouse = so_item and so_item[0]["warehouse"] or ""
 		return so_qty, so_warehouse
 
-	def check_stop_sales_order(self, ref_fieldname):
+	def check_stop_or_close_sales_order(self, ref_fieldname):
 		for d in self.get("items"):
 			if d.get(ref_fieldname):
 				status = frappe.db.get_value("Sales Order", d.get(ref_fieldname), "status")
 				if status == "Stopped":
 					frappe.throw(_("Sales Order {0} is stopped").format(d.get(ref_fieldname)))
+				if status == "Closed":
+					frappe.throw(_("Sales Order {0} is closed").format(d.get(ref_fieldname)))
 
 def check_active_sales_items(obj):
 	for d in obj.get("items"):
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 7a2bdb0..71e5215 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -22,7 +22,7 @@
 			if(doc.status != 'Stopped' && doc.status != 'Closed') {
 				
 				$.each(cur_frm.doc.items, function(i, item){
-					if(item.is_drop_ship == 1){
+					if(item.is_drop_ship == 1 || item.supplier){
 						flag_drop_ship = true;
 					}
 					else{
@@ -68,7 +68,7 @@
 				}
 				
 				if(flt(doc.per_ordered, 2) < 100 && flag_drop_ship)
-					cur_frm.add_custom_button(__('Make Shipment'), cur_frm.cscript.make_drop_shipment).addClass("btn-primary");
+					cur_frm.add_custom_button(__('Make Purchase Order'), cur_frm.cscript.make_purchase_order).addClass("btn-primary");
 
 			} else {
 				// un-stop
@@ -166,12 +166,17 @@
 			}
 		});
 	},
-	make_drop_shipment: function(){
+	make_purchase_order: function(){
 		var dialog = new frappe.ui.Dialog({
 			title: __("For Supplier"),
 			fields: [
 				{"fieldtype": "Link", "label": __("Supplier"), "fieldname": "supplier", "options":"Supplier",
-					"reqd": 1 },
+					"get_query": function () {
+						return {
+							query:"erpnext.selling.doctype.sales_order.sales_order.get_supplier",
+							filters: {'parent': cur_frm.doc.name}
+						}
+					}, "reqd": 1 },
 				{"fieldtype": "Button", "label": __("Proceed"), "fieldname": "proceed"},
 			]
 		});
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 0e7ca96..69ec248 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -495,6 +495,8 @@
 		set_missing_values(source, target)
 		
 	def set_missing_values(source, target):
+		target.supplier = for_supplier
+		target.buying_price_list = frappe.get_value("Supplier", for_supplier, "default_price_list") or 'Standard Buying'
 		target.address_display = ""
 		target.contact_display = ""
 		target.contact_mobile = ""
@@ -547,3 +549,32 @@
 	
 
 	return doclist
+
+@frappe.whitelist()
+def get_supplier(doctype, txt, searchfield, start, page_len, filters):
+	supp_master_name = frappe.defaults.get_user_default("supp_master_name")
+	if supp_master_name == "Supplier Name":
+		fields = ["name", "supplier_type"]
+	else:
+		fields = ["name", "supplier_name", "supplier_type"]
+	fields = ", ".join(fields)
+
+	return frappe.db.sql("""select {field} from `tabSupplier`
+		where docstatus < 2
+			and ({key} like %(txt)s
+				or supplier_name like %(txt)s)
+			and name in (select supplier from `tabSales Order Item` where parent = %(parent)s)
+		order by
+			if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
+			if(locate(%(_txt)s, supplier_name), locate(%(_txt)s, supplier_name), 99999),
+			name, supplier_name
+		limit %(start)s, %(page_len)s """.format(**{
+			'field': fields,
+			'key': searchfield
+		}), {
+			'txt': "%%%s%%" % txt,
+			'_txt': txt.replace("%", ""),
+			'start': start,
+			'page_len': page_len,
+			'parent': filters.get('parent')
+		})
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 6339752..70f28c6 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -106,7 +106,7 @@
 		self.set_status()
 		self.so_required()
 		self.validate_proj_cust()
-		self.check_stop_sales_order("against_sales_order")
+		self.check_stop_or_close_sales_order("against_sales_order")
 		self.validate_for_items()
 		self.validate_warehouse()
 		self.validate_uom_is_integer("stock_uom", "qty")
@@ -203,7 +203,7 @@
 
 
 	def on_cancel(self):
-		self.check_stop_sales_order("against_sales_order")
+		self.check_stop_or_close_sales_order("against_sales_order")
 		self.check_next_docstatus()
 
 		self.update_prevdoc_status()