Merge branch 'edge' of github.com:webnotes/erpnext into edge
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.js b/accounts/doctype/purchase_invoice/purchase_invoice.js
index b4fe62e..f4a2e68 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -44,9 +44,12 @@
 		}
 		
 		// TODO: improve this
-		if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name 
-				&& this.frm.doc.price_list_name) {
-			this.price_list_name(callback1);
+		if(this.frm.doc.__islocal) {
+			if (this.frm.fields_dict.price_list_name && this.frm.doc.price_list_name) {
+				this.price_list_name(callback1);
+			} else {
+				callback1(doc, dt, dn);
+			}
 		}
 	}
 });
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index 7068c72..e5e53f2 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -108,6 +108,8 @@
 		self.update_time_log_batch(self.doc.name)
 		self.convert_to_recurring()
 
+	def before_cancel(self):
+		self.update_time_log_batch(None)
 
 	def on_cancel(self):
 		if cint(self.doc.is_pos) == 1:
@@ -122,8 +124,7 @@
 		sales_com_obj.check_stop_sales_order(self)
 		self.check_next_docstatus()
 		sales_com_obj.update_prevdoc_detail(0, self)
-
-		self.update_time_log_batch(None)
+		
 		self.make_gl_entries(is_cancel=1)
 
 	def on_update_after_submit(self):
diff --git a/accounts/doctype/sales_invoice/test_sales_invoice.py b/accounts/doctype/sales_invoice/test_sales_invoice.py
index 9059978..fb290d2 100644
--- a/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -33,10 +33,10 @@
 		tlb = webnotes.bean("Time Log Batch", "_T-Time Log Batch-00001")
 		tlb.submit()
 		
-		w = webnotes.bean(webnotes.copy_doclist(test_records[0]))
-		w.doclist[1].time_log_batch = "_T-Time Log Batch-00001"
-		w.insert()
-		w.submit()
+		si = webnotes.bean(webnotes.copy_doclist(test_records[0]))
+		si.doclist[1].time_log_batch = "_T-Time Log Batch-00001"
+		si.insert()
+		si.submit()
 		
 		self.assertEquals(webnotes.conn.get_value("Time Log Batch", "_T-Time Log Batch-00001", "status"), 
 			"Billed")
@@ -44,7 +44,7 @@
 		self.assertEquals(webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), 
 			"Billed")
 
-		w.cancel()
+		si.cancel()
 
 		self.assertEquals(webnotes.conn.get_value("Time Log Batch", "_T-Time Log Batch-00001", "status"), 
 			"Submitted")
diff --git a/buying/doctype/purchase_order/purchase_order.js b/buying/doctype/purchase_order/purchase_order.js
index 4bcd828..afe4741 100644
--- a/buying/doctype/purchase_order/purchase_order.js
+++ b/buying/doctype/purchase_order/purchase_order.js
@@ -50,9 +50,12 @@
 		}
 		
 		// TODO: improve this
-		if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name 
-				&& this.frm.doc.price_list_name) {
-			this.price_list_name(callback1);
+		if(this.frm.doc.__islocal) {
+			if (this.frm.fields_dict.price_list_name && this.frm.doc.price_list_name) {
+				this.price_list_name(callback1);
+			} else {
+				callback1(doc, dt, dn);
+			}
 		}
 	}
 	
diff --git a/buying/doctype/supplier_quotation/supplier_quotation.js b/buying/doctype/supplier_quotation/supplier_quotation.js
index 36f9be8..1e4f6cb 100644
--- a/buying/doctype/supplier_quotation/supplier_quotation.js
+++ b/buying/doctype/supplier_quotation/supplier_quotation.js
@@ -40,9 +40,12 @@
 		}
 		
 		// TODO: improve this
-		if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name 
-				&& this.frm.doc.price_list_name) {
-			this.price_list_name(callback);
+		if(this.frm.doc.__islocal) {
+			if (this.frm.fields_dict.price_list_name && this.frm.doc.price_list_name) {
+				this.price_list_name(callback);
+			} else {
+				callback(doc, dt, dn);
+			}
 		}
 	}
 	
diff --git a/patches/february_2013/p09_timesheets.py b/patches/february_2013/p09_timesheets.py
index b61566f..2242d6b 100644
--- a/patches/february_2013/p09_timesheets.py
+++ b/patches/february_2013/p09_timesheets.py
@@ -2,9 +2,31 @@
 
 def execute():
 	# convert timesheet details to time logs
+	webnotes.reload_doc("projects", "doctype", "time_log")
+	
+	# copy custom fields
+	custom_map = {"Timesheet":[], "Timesheet Detail":[]}
+	for custom_field in webnotes.conn.sql("""select * from `tabCustom Field` where 
+		dt in ('Timesheet', 'Timesheet Detail')""", as_dict=True):
+		custom_map[custom_field.dt].append(custom_field.fieldname)
+		custom_field.doctype = "Custom Field"
+		custom_field.dt = "Time Log"
+		custom_field.insert_after = None
+		try:
+			cf = webnotes.bean(custom_field).insert()
+		except Exception, e:
+			# duplicate custom field
+			pass
+	
 	for name in webnotes.conn.sql_list("""select name from tabTimesheet"""):
 		ts = webnotes.bean("Timesheet", name)
+		
 		for tsd in ts.doclist.get({"doctype":"Timesheet Detail"}):
+			if not webnotes.conn.exists("Project", tsd.project_name):
+				tsd.project_name = None
+			if not webnotes.conn.exists("Task", tsd.task_id):
+				tsd.task_id = None
+				
 			tl = webnotes.bean({
 				"doctype": "Time Log",
 				"status": "Draft",
@@ -15,6 +37,19 @@
 				"project": tsd.project_name,
 				"note": ts.doc.notes,
 				"file_list": ts.doc.file_list,
-				"_user_tags": ts.doc._user_tags
+				"_user_tags": ts.doc._user_tags,
+				"owner": ts.doc.owner,
+				"creation": ts.doc.creation,
+				"modified_by": ts.doc.modified_by
 			})
-			tl.insert()
\ No newline at end of file
+			
+			for key in custom_map["Timesheet"]:
+				tl.doc.fields[key] = ts.doc.fields.get(key)
+
+			for key in custom_map["Timesheet Detail"]:
+				tl.doc.fields[key] = tsd.fields.get(key)
+			
+			tl.make_obj()
+			tl.controller.set_status()
+			tl.controller.calculate_total_hours()
+			tl.doc.insert()
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 0870cee..2bd4ad8 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -200,7 +200,8 @@
 	'execute:webnotes.reload_doc("accounts", "Print Format", "Sales Invoice Modern") # 2013-02-26',
 	'execute:webnotes.reload_doc("accounts", "Print Format", "Sales Invoice Spartan") # 2013-02-26',
 	"execute:(not webnotes.conn.exists('Role', 'Projects Manager')) and webnotes.doc({'doctype':'Role', 'role_name':'Projects Manager'}).insert()",
-	"execute:(not webnotes.conn.exists('UOM', 'Hour')) and webnotes.doc({'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Hour'}).insert()",
 	"patches.february_2013.p09_remove_cancelled_warehouses",
 	"patches.march_2013.update_po_prevdoc_doctype",
+	"patches.february_2013.p09_timesheets",
+	"execute:(not webnotes.conn.exists('UOM', 'Hour')) and webnotes.doc({'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'}).insert()",
 ]
\ No newline at end of file
diff --git a/projects/doctype/time_log/time_log.py b/projects/doctype/time_log/time_log.py
index 870c51c..fe5d287 100644
--- a/projects/doctype/time_log/time_log.py
+++ b/projects/doctype/time_log/time_log.py
@@ -68,7 +68,7 @@
 		}, as_dict=True, update={"allDay": 0})
 		
 	for d in data:
-		d.title = d.name + ": " + d.activity_type
+		d.title = d.name + ": " + (d.activity_type or "[Activity Type not set]")
 		if d.task:
 			d.title += " for Task: " + d.task
 		if d.project:
diff --git a/projects/doctype/time_log/time_log.txt b/projects/doctype/time_log/time_log.txt
index 0e52464..cf815db 100644
--- a/projects/doctype/time_log/time_log.txt
+++ b/projects/doctype/time_log/time_log.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-26 14:58:28", 
+  "creation": "2013-03-04 02:39:45", 
   "docstatus": 0, 
-  "modified": "2013-03-01 17:48:09", 
+  "modified": "2013-03-04 02:48:12", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -31,7 +31,6 @@
   "parenttype": "DocType", 
   "permlevel": 0, 
   "read": 1, 
-  "report": 1, 
   "write": 1
  }, 
  {
@@ -166,6 +165,12 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "column_break_16", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "file_list", 
   "fieldtype": "Text", 
   "hidden": 1, 
@@ -185,18 +190,13 @@
   "print_hide": 1
  }, 
  {
-  "cancel": 0, 
   "create": 1, 
   "doctype": "DocPerm", 
   "match": "owner", 
-  "role": "Projects User", 
-  "submit": 1
+  "role": "Projects User"
  }, 
  {
-  "amend": 1, 
-  "cancel": 1, 
   "doctype": "DocPerm", 
-  "role": "Projects Manager", 
-  "submit": 0
+  "role": "Projects Manager"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js
index c7d2e50..82e494c 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -45,9 +45,11 @@
 		}
 		
 		// TODO: improve this
-		if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name 
-				&& this.frm.doc.price_list_name) {
-			this.price_list_name(callback);
+		if(this.frm.doc.__islocal) {
+			if (this.frm.fields_dict.price_list_name && this.frm.doc.price_list_name) 
+				this.price_list_name(callback);
+			else
+				callback(doc, dt, dn);
 		}
 	}
 });