fixes in Purchase Invoice
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 0f1eb4b..edbefba 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -77,14 +77,6 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "project", 
-   "fieldtype": "Link", 
-   "label": "Project", 
-   "options": "Project", 
-   "permlevel": 0, 
-   "precision": ""
-  }, 
-  {
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "oldfieldtype": "Column Break", 
@@ -946,7 +938,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-04-27 20:32:12.436976", 
+ "modified": "2015-04-30 03:05:13.790265", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice", 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 31213af..c0ebf68 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -377,11 +377,14 @@
 		self.update_project()
 		
 	def update_project(self):
-		if self.project and frappe.db.exists("Project", self.project):
-			project = frappe.get_doc("Project", self.project)
-			project.flags.dont_sync_tasks = True
-			project.update_purchase_costing()
-			project.save()
+		project_list = []
+		for d in self.items:
+			if d.project_name and d.project_name not in project_list:
+				project = frappe.get_doc("Project", d.project_name)
+				project.flags.dont_sync_tasks = True
+				project.update_purchase_costing()
+				project.save()
+				project_list.append(d.project_name)
 
 @frappe.whitelist()
 def get_expense_account(doctype, txt, searchfield, start, page_len, filters):
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index d0fb3d9..7f46b08 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -238,13 +238,13 @@
 		purchase_invoice = frappe.new_doc('Purchase Invoice')
 		purchase_invoice.update({
 			"credit_to": "_Test Payable - _TC",
-			"project": "_Test Project",
 			"supplier": "_Test Supplier",
 			"company": "_Test Company",
 			"items": [
 				{
 					"rate": 500,
 					"qty": 1,
+					"project_name": "_Test Project",
 					"item_code": "_Test Item Home Desktop 100",
 					"expense_account": "_Test Account Cost for Goods Sold - _TC",
 					"cost_center": "_Test Cost Center - _TC"
@@ -252,6 +252,7 @@
 				{
 					"rate": 1500,
 					"qty": 1,
+					"project_name": "_Test Project",
 					"item_code": "_Test Item Home Desktop 200",
 					"expense_account": "_Test Account Cost for Goods Sold - _TC",
 					"cost_center": "_Test Cost Center - _TC"
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 839ad1d6..590788d 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -91,8 +91,8 @@
 			self.per_gross_margin = (self.gross_margin / flt(self.total_billing_amount)) *100
 			
 	def update_purchase_costing(self):
-		self.total_purchase_cost = frappe.db.sql("""select sum(grand_total) as cost
-			from `tabPurchase Invoice` where project = %s and docstatus=1 """, self.name, as_dict=1)[0].cost or 0
+		self.total_purchase_cost = frappe.db.sql("""select sum(amount) as cost
+			from `tabPurchase Invoice Item` where project_name = %s and docstatus=1 """, self.name, as_dict=1)[0].cost or 0
 
 @frappe.whitelist()
 def get_cost_center_name(project_name):