Merge branch 'hotfix'
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index ca6d6be..0457b7e 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
 from erpnext.hooks import regional_overrides
 from frappe.utils import getdate
 
-__version__ = '10.1.56'
+__version__ = '10.1.57'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py
index b221a08..5b4356a 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py
@@ -60,7 +60,12 @@
 		for rfq in rfq_list:
 			doc = frappe.get_doc('Request for Quotation', rfq)
 			doc_sup = frappe.get_all('Request for Quotation Supplier', filters=
-				{'parent': doc.name, 'supplier': self.supplier}, fields=['name', 'quote_status'])[0]
+				{'parent': doc.name, 'supplier': self.supplier}, fields=['name', 'quote_status'])
+
+			doc_sup = doc_sup[0] if doc_sup else None
+			if not doc_sup:
+				frappe.throw(_("Supplier {0} not found in {1}").format(self.supplier,
+					"<a href='desk#Form/Request for Quotation/{0}'> Request for Quotation {0} </a>".format(doc.name)))
 
 			quote_status = _('Received')
 			for item in doc.items:
@@ -152,4 +157,4 @@
 		}
 	}, target_doc)
 
-	return doclist
\ No newline at end of file
+	return doclist
diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js
index 11655e9..7065794 100644
--- a/erpnext/public/js/controllers/buying.js
+++ b/erpnext/public/js/controllers/buying.js
@@ -227,6 +227,69 @@
 
 	tc_name: function() {
 		this.get_terms();
+	},
+
+	link_to_mrs: function() {
+		var my_items = [];
+		for (var i in cur_frm.doc.items) {
+			if(!cur_frm.doc.items[i].material_request){
+				my_items.push(cur_frm.doc.items[i].item_code);
+			}
+		}
+		frappe.call({
+			method: "erpnext.buying.utils.get_linked_material_requests",
+			args:{
+				items: my_items
+			},
+			callback: function(r) {
+				if(!r.message) {
+					frappe.throw(__("No pending Material Requests found to link for the given items."))
+				}
+				else {
+					var i = 0;
+					var item_length = cur_frm.doc.items.length;
+					while (i < item_length) {
+						var qty = cur_frm.doc.items[i].qty;
+						(r.message[0] || []).forEach(function(d) {
+							if (d.qty > 0 && qty > 0 && cur_frm.doc.items[i].item_code == d.item_code && !cur_frm.doc.items[i].material_request_item)
+							{
+								cur_frm.doc.items[i].material_request = d.mr_name;
+								cur_frm.doc.items[i].material_request_item = d.mr_item;
+								var my_qty = Math.min(qty, d.qty);
+								qty = qty - my_qty;
+								d.qty = d.qty  - my_qty;
+								cur_frm.doc.items[i].stock_qty = my_qty*cur_frm.doc.items[i].conversion_factor;
+								cur_frm.doc.items[i].qty = my_qty;
+	
+								frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + cur_frm.doc.items[i].idx + ")");
+								if (qty > 0)
+								{
+									frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
+									var newrow = frappe.model.add_child(cur_frm.doc, cur_frm.doc.items[i].doctype, "items");
+									item_length++;
+	
+									for (var key in cur_frm.doc.items[i])
+									{
+										newrow[key] = cur_frm.doc.items[i][key];
+									}
+	
+									newrow.idx = item_length;
+									newrow["stock_qty"] = newrow.conversion_factor*qty;
+									newrow["qty"] = qty;
+	
+									newrow["material_request"] = "";
+									newrow["material_request_item"] = "";
+	
+								}
+							}
+						});
+						i++;
+					}
+					refresh_field("items");
+					//cur_frm.save();
+				}
+			}
+		});
 	}
 });
 
diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py
index dd5c037..50bea41 100644
--- a/erpnext/setup/setup_wizard/operations/taxes_setup.py
+++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py
@@ -50,7 +50,7 @@
 				"tax_rate": flt(tax_rate) if tax_rate else None
 			}).insert(ignore_permissions=True, ignore_mandatory=True)
 		except frappe.NameError:
-			frappe.message_log.pop()
+			if frappe.message_log: frappe.message_log.pop()
 			abbr = frappe.db.get_value('Company', company, 'abbr')
 			account = '{0} - {1}'.format(account_name, abbr)
 			return frappe.get_doc('Account', account)