Merge branch 'staging' into develop
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 4f18687..0b61c90 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/hooks.py b/erpnext/hooks.py
index 925b159..b42dc11 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -12,7 +12,7 @@
 source_link = "https://github.com/frappe/erpnext"
 
 develop_version = '12.x.x-develop'
-staging_version = '11.0.3-beta.8'
+staging_version = '11.0.3-beta.9'
 
 error_report_email = "support@erpnext.com"
 
diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js
index 55fcaab..cefdbe7 100644
--- a/erpnext/public/js/controllers/buying.js
+++ b/erpnext/public/js/controllers/buying.js
@@ -235,6 +235,69 @@
 		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();
+				}
+			}
+		});
+	},
+
 	update_auto_repeat_reference: function(doc) {
 		if (doc.auto_repeat) {
 			frappe.call({
diff --git a/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py b/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py
index b0dfdcb..34ebb72 100644
--- a/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py
+++ b/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py
@@ -7,15 +7,15 @@
 
 def execute(filters=None):
 	return _execute(filters, additional_table_columns=[
-		dict(fieldtype='Data', label='Supplier GSTIN', width=120),
-		dict(fieldtype='Data', label='Company GSTIN', width=120),
-		dict(fieldtype='Data', label='Reverse Charge', width=120),
-		dict(fieldtype='Data', label='Invoice Type', width=120),
-		dict(fieldtype='Data', label='Export Type', width=120),
-		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130),
-		dict(fieldtype='Data', label='HSN Code', width=120),
-		dict(fieldtype='Data', label='Supplier Invoice No', width=120),
-		dict(fieldtype='Date', label='Supplier Invoice Date', width=100)
+		dict(fieldtype='Data', label='Supplier GSTIN', fieldname="supplier_gstin", width=120),
+		dict(fieldtype='Data', label='Company GSTIN', fieldname="company_gstin", width=120),
+		dict(fieldtype='Data', label='Reverse Charge', fieldname="reverse_charge", width=120),
+		dict(fieldtype='Data', label='Invoice Type', fieldname="invoice_type", width=120),
+		dict(fieldtype='Data', label='Export Type', fieldname="export_type", width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', fieldname="ecommerce_gstin", width=130),
+		dict(fieldtype='Data', label='HSN Code', fieldname="hsn_code", width=120),
+		dict(fieldtype='Data', label='Supplier Invoice No', fieldname="supplier_invoice_no", width=120),
+		dict(fieldtype='Date', label='Supplier Invoice Date', fieldname="supplier_invoice_date", width=100)
 	], additional_query_columns=[
 		'supplier_gstin',
 		'company_gstin',
diff --git a/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py b/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py
index 4e57a52..d0b1163 100644
--- a/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py
+++ b/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py
@@ -7,15 +7,15 @@
 
 def execute(filters=None):
 	return _execute(filters, additional_table_columns=[
-		dict(fieldtype='Data', label='Customer GSTIN', width=120),
-		dict(fieldtype='Data', label='Billing Address GSTIN', width=140),
-		dict(fieldtype='Data', label='Company GSTIN', width=120),
-		dict(fieldtype='Data', label='Place of Supply', width=120),
-		dict(fieldtype='Data', label='Reverse Charge', width=120),
-		dict(fieldtype='Data', label='Invoice Type', width=120),
-		dict(fieldtype='Data', label='Export Type', width=120),
-		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130),
-		dict(fieldtype='Data', label='HSN Code', width=120)
+		dict(fieldtype='Data', label='Customer GSTIN', fieldname="customer_gstin", width=120),
+		dict(fieldtype='Data', label='Billing Address GSTIN', fieldname="billing_address_gstin", width=140),
+		dict(fieldtype='Data', label='Company GSTIN', fieldname="company_gstin", width=120),
+		dict(fieldtype='Data', label='Place of Supply', fieldname="place_of_supply", width=120),
+		dict(fieldtype='Data', label='Reverse Charge', fieldname="reverse_charge", width=120),
+		dict(fieldtype='Data', label='Invoice Type', fieldname="invoice_type", width=120),
+		dict(fieldtype='Data', label='Export Type', fieldname="export_type", width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', fieldname="ecommerce_gstin", width=130),
+		dict(fieldtype='Data', label='HSN Code', fieldname="hsn_code", width=120)
 	], additional_query_columns=[
 		'customer_gstin',
 		'billing_address_gstin',
diff --git a/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py b/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py
index 8d479a9..59df553 100644
--- a/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py
+++ b/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py
@@ -7,12 +7,12 @@
 
 def execute(filters=None):
 	return _execute(filters, additional_table_columns=[
-		dict(fieldtype='Data', label='Supplier GSTIN', width=120),
-		dict(fieldtype='Data', label='Company GSTIN', width=120),
-		dict(fieldtype='Data', label='Reverse Charge', width=120),
-		dict(fieldtype='Data', label='Invoice Type', width=120),
-		dict(fieldtype='Data', label='Export Type', width=120),
-		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130)
+		dict(fieldtype='Data', label='Supplier GSTIN', fieldname="supplier_gstin", width=120),
+		dict(fieldtype='Data', label='Company GSTIN', fieldname="company_gstin", width=120),
+		dict(fieldtype='Data', label='Reverse Charge', fieldname="reverse_charge", width=120),
+		dict(fieldtype='Data', label='Invoice Type', fieldname="invoice_type", width=120),
+		dict(fieldtype='Data', label='Export Type', fieldname="export_type", width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', fieldname="ecommerce_gstin", width=130)
 	], additional_query_columns=[
 		'supplier_gstin',
 		'company_gstin',
diff --git a/erpnext/regional/report/gst_sales_register/gst_sales_register.py b/erpnext/regional/report/gst_sales_register/gst_sales_register.py
index e79d722..4b32081 100644
--- a/erpnext/regional/report/gst_sales_register/gst_sales_register.py
+++ b/erpnext/regional/report/gst_sales_register/gst_sales_register.py
@@ -7,14 +7,14 @@
 
 def execute(filters=None):
 	return _execute(filters, additional_table_columns=[
-		dict(fieldtype='Data', label='Customer GSTIN', width=120),
-		dict(fieldtype='Data', label='Billing Address GSTIN', width=140),
-		dict(fieldtype='Data', label='Company GSTIN', width=120),
-		dict(fieldtype='Data', label='Place of Supply', width=120),
-		dict(fieldtype='Data', label='Reverse Charge', width=120),
-		dict(fieldtype='Data', label='Invoice Type', width=120),
-		dict(fieldtype='Data', label='Export Type', width=120),
-		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130)
+		dict(fieldtype='Data', label='Customer GSTIN', fieldname="customer_gstin", width=120),
+		dict(fieldtype='Data', label='Billing Address GSTIN', fieldname="billing_address_gstin", width=140),
+		dict(fieldtype='Data', label='Company GSTIN', fieldname="company_gstin", width=120),
+		dict(fieldtype='Data', label='Place of Supply', fieldname="place_of_supply", width=120),
+		dict(fieldtype='Data', label='Reverse Charge', fieldname="reverse_charge", width=120),
+		dict(fieldtype='Data', label='Invoice Type', fieldname="invoice_type", width=120),
+		dict(fieldtype='Data', label='Export Type', fieldname="export_type", width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', fieldname="ecommerce_gstin", width=130)
 	], additional_query_columns=[
 		'customer_gstin',
 		'billing_address_gstin',
diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py
index e0efda0..8bcec52 100644
--- a/erpnext/setup/setup_wizard/operations/taxes_setup.py
+++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py
@@ -98,4 +98,4 @@
 	with open (os.path.join(os.path.dirname(__file__), "..", "data", "country_wise_tax.json")) as countrywise_tax:
 		data = json.load(countrywise_tax).get(country)
 
-	return data
\ No newline at end of file
+	return data