Fixes for subcontracting
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 43276e5..ad56d8f 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -256,7 +256,7 @@
 
 			rm_supplied_idx += 1
 
-			raw_materials_cost += required_qty * flt(item.rate)
+			raw_materials_cost += required_qty * flt(bom_item.rate)
 
 		if self.doctype == "Purchase Receipt":
 			item.rm_supp_cost = raw_materials_cost
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 0aa3acc..77de44d 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -94,8 +94,9 @@
 		pr.run_method("calculate_taxes_and_totals")
 		pr.insert()
 
-		self.assertEquals(pr.get("purchase_receipt_details")[0].rm_supp_cost, 70000.0)
 		self.assertEquals(len(pr.get("pr_raw_material_details")), 2)
+		self.assertEquals(pr.get("purchase_receipt_details")[0].rm_supp_cost, 70000.0)
+
 
 	def test_serial_no_supplier(self):
 		pr = frappe.copy_doc(test_records[0])