Merge branch 'master' into edge

Conflicts:
	setup/doctype/backup_manager/backup_dropbox.py
diff --git a/accounts/doctype/journal_voucher/journal_voucher.txt b/accounts/doctype/journal_voucher/journal_voucher.txt
index b36008e..dc857c8 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.txt
+++ b/accounts/doctype/journal_voucher/journal_voucher.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-30 12:49:46", 
+  "creation": "2013-03-07 12:35:57", 
   "docstatus": 0, 
-  "modified": "2013-02-01 10:50:16", 
+  "modified": "2013-03-21 13:02:27", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -24,6 +24,9 @@
   "permlevel": 0
  }, 
  {
+  "amend": 1, 
+  "cancel": 1, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Journal Voucher", 
@@ -31,7 +34,9 @@
   "parenttype": "DocType", 
   "permlevel": 0, 
   "read": 1, 
-  "report": 1
+  "report": 1, 
+  "submit": 1, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -278,6 +283,7 @@
  }, 
  {
   "default": "No", 
+  "description": "Considered as Opening Balance", 
   "doctype": "DocField", 
   "fieldname": "is_opening", 
   "fieldtype": "Select", 
@@ -290,7 +296,7 @@
   "search_index": 1
  }, 
  {
-  "description": "For opening invoice entry, this date will reflect in the period-wise aging report.", 
+  "description": "Actual Posting Date", 
   "doctype": "DocField", 
   "fieldname": "aging_date", 
   "fieldtype": "Date", 
@@ -444,30 +450,11 @@
   "read_only": 1
  }, 
  {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "role": "Accounts User", 
-  "submit": 1, 
-  "write": 1
+  "role": "Accounts Manager"
  }, 
  {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "role": "Accounts Manager", 
-  "submit": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "role": "Auditor", 
-  "submit": 0, 
-  "write": 0
+  "role": "Accounts User"
  }
 ]
\ No newline at end of file
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.txt b/accounts/doctype/purchase_invoice/purchase_invoice.txt
index 0c921b1..4228264 100755
--- a/accounts/doctype/purchase_invoice/purchase_invoice.txt
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-29 17:54:09", 
+  "creation": "2013-03-07 13:16:13", 
   "docstatus": 0, 
-  "modified": "2013-01-29 18:25:24", 
+  "modified": "2013-03-22 18:17:14", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -636,6 +636,7 @@
  }, 
  {
   "default": "No", 
+  "description": "Considered as Opening Balance", 
   "doctype": "DocField", 
   "fieldname": "is_opening", 
   "fieldtype": "Select", 
@@ -648,6 +649,7 @@
   "search_index": 1
  }, 
  {
+  "description": "Actual Invoice Date", 
   "doctype": "DocField", 
   "fieldname": "aging_date", 
   "fieldtype": "Date", 
@@ -774,40 +776,8 @@
   "write": 1
  }, 
  {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "role": "Purchase User", 
-  "submit": 0, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
   "doctype": "DocPerm", 
   "match": "supplier", 
-  "role": "Supplier", 
-  "submit": 0, 
-  "write": 0
- }, 
- {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "role": "Accounts Manager", 
-  "submit": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "role": "Auditor", 
-  "submit": 0, 
-  "write": 0
+  "role": "Supplier"
  }
 ]
\ No newline at end of file
diff --git a/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.txt b/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.txt
index 62ee960..b593b81 100644
--- a/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.txt
+++ b/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.txt
@@ -1,10 +1,10 @@
 [
  {
-  "creation": "2013-02-22 01:27:40", 
+  "creation": "2013-03-08 15:36:47", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:29", 
+  "modified": "2013-03-22 16:45:28", 
   "modified_by": "Administrator", 
-  "owner": "wasim@webnotestech.com"
+  "owner": "Administrator"
  }, 
  {
   "autoname": "PVTD.######", 
@@ -27,6 +27,17 @@
   "name": "Purchase Taxes and Charges"
  }, 
  {
+  "default": "Valuation and Total", 
+  "doctype": "DocField", 
+  "fieldname": "category", 
+  "fieldtype": "Select", 
+  "label": "Consider Tax or Charge for", 
+  "oldfieldname": "category", 
+  "oldfieldtype": "Select", 
+  "options": "Valuation and Total\nValuation\nTotal", 
+  "reqd": 1
+ }, 
+ {
   "doctype": "DocField", 
   "fieldname": "charge_type", 
   "fieldtype": "Select", 
@@ -106,17 +117,6 @@
   "oldfieldtype": "Data"
  }, 
  {
-  "default": "Valuation and Total", 
-  "doctype": "DocField", 
-  "fieldname": "category", 
-  "fieldtype": "Select", 
-  "label": "Consider Tax or Charge for", 
-  "oldfieldname": "category", 
-  "oldfieldtype": "Select", 
-  "options": "Valuation and Total\nValuation\nTotal", 
-  "reqd": 1
- }, 
- {
   "default": "Add", 
   "doctype": "DocField", 
   "fieldname": "add_deduct_tax", 
diff --git a/accounts/doctype/sales_invoice/sales_invoice.txt b/accounts/doctype/sales_invoice/sales_invoice.txt
index 462565c..cf6e994 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.txt
+++ b/accounts/doctype/sales_invoice/sales_invoice.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-20 17:01:58", 
+  "creation": "2013-03-22 18:37:25", 
   "docstatus": 0, 
-  "modified": "2013-03-20 19:17:38", 
+  "modified": "2013-03-22 18:38:13", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -750,11 +750,12 @@
  }, 
  {
   "default": "No", 
+  "description": "Considered as an Opening Balance", 
   "doctype": "DocField", 
   "fieldname": "is_opening", 
   "fieldtype": "Select", 
   "in_filter": 1, 
-  "label": "Is Opening", 
+  "label": "Is Opening Entry", 
   "oldfieldname": "is_opening", 
   "oldfieldtype": "Select", 
   "options": "No\nYes", 
@@ -762,6 +763,7 @@
   "search_index": 0
  }, 
  {
+  "description": "Actual Invoice Date", 
   "doctype": "DocField", 
   "fieldname": "aging_date", 
   "fieldtype": "Date", 
diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py
index d98c8a7..16ecb6d 100644
--- a/hr/doctype/employee/employee.py
+++ b/hr/doctype/employee/employee.py
@@ -71,7 +71,9 @@
 		webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id)
 		webnotes.conn.set_default("employee_name", self.doc.employee_name, self.doc.user_id)
 		webnotes.conn.set_default("company", self.doc.company, self.doc.user_id)
-		
+		if self.doc.reports_to:
+			webnotes.conn.set_default("leave_approver", webnotes.conn.get_value("Employee", self.doc.reports_to, "user_id"), self.doc.user_id)
+
 	def update_profile(self):
 		# add employee role if missing
 		if not "Employee" in webnotes.conn.sql_list("""select role from tabUserRole
diff --git a/setup/doctype/backup_manager/backup_dropbox.py b/setup/doctype/backup_manager/backup_dropbox.py
index ebadeab..4e9efdf 100644
--- a/setup/doctype/backup_manager/backup_dropbox.py
+++ b/setup/doctype/backup_manager/backup_dropbox.py
@@ -61,7 +61,7 @@
 	webnotes.response['page_name'] = 'message.html'
 
 def backup_to_dropbox():
-	from dropbox import client, session, rest
+	from dropbox import client, session
 	from conf import dropbox_access_key, dropbox_secret_key
 	from webnotes.utils.backups import new_backup
 	if not webnotes.conn:
@@ -81,24 +81,23 @@
 	upload_file_to_dropbox(filename, "database", dropbox_client)
 
 	response = dropbox_client.metadata("/files")
-
 	# upload files to files folder
-	filename = os.path.join(get_base_path(), "public", "files")
-	for filename in os.listdir(filename):
+	path = os.path.join(get_base_path(), "public", "files")
+	for filename in os.listdir(path):
 		found = False
+		filepath = os.path.join(path, filename)
 		for file_metadata in response["contents"]:
- 			if filename==os.path.basename(file_metadata["path"]):
-				if os.stat(filename).st_size==file_metadata["bytes"]:
-					found=True
-		
+ 			if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(filepath).st_size == int(file_metadata["bytes"]):
+				found = True
+				break
 		if not found:
-			upload_file_to_dropbox(os.path.join(get_base_path(),"public", "files", filename), "files", dropbox_client)
+			upload_file_to_dropbox(filepath, "files", dropbox_client)
 
 def get_dropbox_session():
 	from dropbox import session
 	try:
 		from conf import dropbox_access_key, dropbox_secret_key
-	except ImportError, e:
+	except ImportError:
 		webnotes.msgprint(_("Please set Dropbox access keys in") + " conf.py", 
 		raise_exception=True)
 	sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")
@@ -113,11 +112,11 @@
 		while uploader.offset < size:
 			try:
 				uploader.upload_chunked()
-				uploader.finish(folder + '/' + os.path.basename(filename), overwrite='True')
-			except rest.ErrorResponse, e:
+				uploader.finish(os.path.join(folder, os.path.basename(filename)), overwrite=True)
+			except rest.ErrorResponse:
 				pass
 	else:
-		response = dropbox_client.put_file(folder + "/" + os.path.basename(filename), f, overwrite=True)
+		dropbox_client.put_file(os.path.join(folder, os.path.basename(filename)), f, overwrite=True)
 
 if __name__=="__main__":
 	backup_to_dropbox()
\ No newline at end of file
diff --git a/setup/doctype/backup_manager/backup_googledrive.py b/setup/doctype/backup_manager/backup_googledrive.py
index c794672..a767b3a 100644
--- a/setup/doctype/backup_manager/backup_googledrive.py
+++ b/setup/doctype/backup_manager/backup_googledrive.py
@@ -51,8 +51,6 @@
 
 def backup_to_gdrive():
 	from webnotes.utils.backups import new_backup
-	found_database = False
-	found_files = False
 	if not webnotes.conn:
 		webnotes.connect()
 	flow = get_gdrive_flow()
@@ -73,10 +71,11 @@
 
 	# upload files to files folder
 	path = os.path.join(get_base_path(), "public", "files")
-	for files in os.listdir(path):
-		filename = path + "/" + files
+	for filename in os.listdir(path):
+		found = False
+		filepath = os.path.join(path, filename)
 		ext = filename.split('.')[-1]
-		size = os.path.getsize(filename)
+		size = os.path.getsize(filepath)
 		if ext == 'gz' or ext == 'gzip':
 			mimetype = 'application/x-gzip'
 		else:
@@ -88,11 +87,11 @@
 			**param).execute()
 	  	for child in children.get('items', []):
 			file = drive_service.files().get(fileId=child['id']).execute()
-			if files == file['title'] and size == int(file['fileSize']):
-				found_files = True
+			if filename == file['title'] and size == int(file['fileSize']):
+				found = True
 				break
-		if not found_files:
-			upload_files(filename, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
+		if not found:
+			upload_files(filepath, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
 
 def get_gdrive_flow():
 	from oauth2client.client import OAuth2WebServerFlow
@@ -106,10 +105,9 @@
 	#	+ "?cmd=setup.doctype.backup_manager.backup_googledrive.googledrive_callback"
 	
 	# for installed apps since google does not support subdomains
-	redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
 	
 	flow = OAuth2WebServerFlow(conf.gdrive_client_id, conf.gdrive_client_secret, 
-		"https://www.googleapis.com/auth/drive", redirect_uri)
+		"https://www.googleapis.com/auth/drive", 'urn:ietf:wg:oauth:2.0:oob')
 	return flow
 	
 @webnotes.whitelist()
diff --git a/website/doctype/contact_us_settings/contact_us_settings.py b/website/doctype/contact_us_settings/contact_us_settings.py
index 740b651..8716e60 100644
--- a/website/doctype/contact_us_settings/contact_us_settings.py
+++ b/website/doctype/contact_us_settings/contact_us_settings.py
@@ -10,9 +10,9 @@
 	def onload(self):
 		"""load address"""
 		if self.doc.query_options:
-			self.doc.query_options = filter(None, self.doc.query_options.replace(",", "\n").split())
+			self.query_options = filter(None, self.doc.query_options.replace(",", "\n").split())
 		else:
-			self.doc.query_options = ["Sales", "Support", "General"]
+			self.query_options = ["Sales", "Support", "General"]
 		if self.doc.address:
 			self.address = webnotes.bean("Address", self.doc.address).doc
 			
diff --git a/website/templates/pages/contact.html b/website/templates/pages/contact.html
index 204b6df..79bcb04 100644
--- a/website/templates/pages/contact.html
+++ b/website/templates/pages/contact.html
@@ -19,7 +19,7 @@
 			</div>
 			<div class="clearfix"></div>
 			<p><select class="span6" name="subject">
-				{% for option in obj.doc.query_options %}
+				{% for option in obj.query_options %}
 					<option value="{{ option }}">{{ option }}</option>
 				{% endfor %}
 			</select></p>
diff --git a/website/utils.py b/website/utils.py
index 94c9e87..14e3e13 100644
--- a/website/utils.py
+++ b/website/utils.py
@@ -143,6 +143,7 @@
 				args.update(webnotes.get_method(target)())
 			else:
 				args.obj = webnotes.bean(page_settings_map[page_name]).obj
+
 	else:
 		args = get_doc_fields(page_name)