Merge remote-tracking branch 'upstream/wsgi' into HEAD

Conflicts:
	public/js/complete_setup.js
	setup/doctype/setup_control/setup_control.py
diff --git a/patches/october_2013/p01_fix_serial_no_status.py b/patches/october_2013/p01_fix_serial_no_status.py
index 0bfc400..9f58593 100644
--- a/patches/october_2013/p01_fix_serial_no_status.py
+++ b/patches/october_2013/p01_fix_serial_no_status.py
@@ -3,16 +3,19 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import flt
 
 def execute():	
 	serial_nos = webnotes.conn.sql("""select name from `tabSerial No` where status!='Not in Use' 
 		and docstatus=0""")
 	for sr in serial_nos:
-		sr_bean = webnotes.bean("Serial No", sr[0])
-		sr_bean.make_controller().via_stock_ledger = True
-		sr_bean.run_method("validate")
-		sr_bean.save()
+		try:
+			sr_bean = webnotes.bean("Serial No", sr[0])
+			sr_bean.make_controller().via_stock_ledger = True
+			sr_bean.run_method("validate")
+			sr_bean.save()
+			webnotes.conn.commit()
+		except:
+			pass
 			
 	webnotes.conn.sql("""update `tabSerial No` set warehouse='' where status in 
 		('Delivered', 'Purchase Returned')""")
\ No newline at end of file
diff --git a/patches/october_2013/p06_update_control_panel_and_global_defaults.py b/patches/october_2013/p06_update_control_panel_and_global_defaults.py
new file mode 100644
index 0000000..8c12107
--- /dev/null
+++ b/patches/october_2013/p06_update_control_panel_and_global_defaults.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+def execute():
+	webnotes.reload_doc("setup", "doctype", "global_defaults")
+
+	country = webnotes.conn.sql("""select value from `tabSingles` where 
+		field='country' and doctype='Control Panel'""")
+	time_zone = webnotes.conn.sql("""select value from `tabSingles` where 
+		field='timezone' and doctype='Control Panel'""")
+
+	try:
+		gb_bean = webnotes.bean("Global Defaults")
+		gb_bean.doc.country = country and country[0][0] or None
+		gb_bean.doc.time_zone = time_zone and time_zone[0][0] or None
+		gb_bean.save()
+	except:
+		pass
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 5138b47..63f06f7 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -234,4 +234,5 @@
 	"patches.october_2013.p03_remove_sales_and_purchase_return_tool",
 	"patches.october_2013.p04_update_report_permission",
 	"patches.october_2013.p05_delete_gl_entries_for_cancelled_vouchers",
+	"patches.october_2013.p06_update_control_panel_and_global_defaults",
 ]
\ No newline at end of file
diff --git a/setup/doctype/global_defaults/global_defaults.js b/setup/doctype/global_defaults/global_defaults.js
index 3999979..8856acb 100644
--- a/setup/doctype/global_defaults/global_defaults.js
+++ b/setup/doctype/global_defaults/global_defaults.js
@@ -1,9 +1,47 @@
 // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
 // License: GNU General Public License v3. See license.txt
 
-// Validate
-cur_frm.cscript.validate = function(doc, cdt, cdn) {
-	return $c_obj(make_doclist(cdt, cdn), 'get_defaults', '', function(r, rt){
-		sys_defaults = r.message;
-	});
-}
\ No newline at end of file
+$.extend(cur_frm.cscript, {
+	onload: function(doc) {
+		var me = this;
+		this.timezone = doc.time_zone;
+		
+		wn.call({
+			method:"webnotes.country_info.get_country_timezone_info",
+			callback: function(data) {
+				erpnext.country_info = data.message.country_info;
+				erpnext.all_timezones = data.message.all_timezones;
+				me.set_timezone_options();
+				cur_frm.set_value("time_zone", me.timezone);
+			}
+		});
+	},
+
+	validate: function(doc, cdt, cdn) {
+		return $c_obj(make_doclist(cdt, cdn), 'get_defaults', '', function(r, rt){
+			sys_defaults = r.message;
+		});
+	},
+
+	country: function() {
+		var me = this;
+		var timezones = [];
+
+		if (this.frm.doc.country) {
+			var timezones = (erpnext.country_info[this.frm.doc.country].timezones || []).sort();
+		}
+
+		this.frm.set_value("time_zone", timezones[0]);
+		this.set_timezone_options(timezones);
+	},
+
+	set_timezone_options: function(filtered_options) {
+		var me = this;
+		if(!filtered_options) filtered_options = [];
+		var remaining_timezones = $.map(erpnext.all_timezones, function(v) 
+			{ return filtered_options.indexOf(v)===-1 ? v : null; });
+
+		this.frm.set_df_property("time_zone", "options", 
+			(filtered_options.concat([""]).concat(remaining_timezones)).join("\n"));
+	}
+});
\ No newline at end of file
diff --git a/setup/doctype/global_defaults/global_defaults.py b/setup/doctype/global_defaults/global_defaults.py
index 1b1d50c..fb16b13 100644
--- a/setup/doctype/global_defaults/global_defaults.py
+++ b/setup/doctype/global_defaults/global_defaults.py
@@ -29,6 +29,7 @@
 	def on_update(self):
 		"""update defaults"""
 		self.validate_session_expiry()
+		self.update_control_panel()
 		
 		for key in keydict:
 			webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], ''))
@@ -57,7 +58,15 @@
 			if len(parts)!=2 or not (cint(parts[0]) or cint(parts[1])):
 				webnotes.msgprint("""Session Expiry must be in format hh:mm""",
 					raise_exception=1)
-				
-	
+
+	def update_control_panel(self):
+		cp_bean = webnotes.bean("Control Panel")
+		if self.doc.country:
+			cp_bean.doc.country = self.doc.country
+		if self.doc.time_zone:
+			cp_bean.doc.time_zone = self.doc.time_zone
+		cp_bean.ignore_permissions = True
+		cp_bean.save()
+
 	def get_defaults(self):
 		return webnotes.defaults.get_defaults()
diff --git a/setup/doctype/global_defaults/global_defaults.txt b/setup/doctype/global_defaults/global_defaults.txt
index a8a80b1..da40a19 100644
--- a/setup/doctype/global_defaults/global_defaults.txt
+++ b/setup/doctype/global_defaults/global_defaults.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-02 17:53:24", 
   "docstatus": 0, 
-  "modified": "2013-10-23 10:22:44", 
+  "modified": "2013-10-23 18:06:04", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -155,6 +155,13 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "country", 
+  "fieldtype": "Select", 
+  "label": "Country", 
+  "options": "link:Country"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "sms_sender_name", 
   "fieldtype": "Data", 
   "label": "SMS Sender Name", 
@@ -176,6 +183,12 @@
   "read_only": 0
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "time_zone", 
+  "fieldtype": "Select", 
+  "label": "Time Zone"
+ }, 
+ {
   "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py
index 9496d6a..b36cf0c 100644
--- a/stock/doctype/serial_no/serial_no.py
+++ b/stock/doctype/serial_no/serial_no.py
@@ -39,19 +39,14 @@
 		self.on_stock_ledger_entry()
 
 	def validate_amc_status(self):
-		"""
-			validate amc status
-		"""
 		if (self.doc.maintenance_status == 'Out of AMC' and self.doc.amc_expiry_date and getdate(self.doc.amc_expiry_date) >= datetime.date.today()) or (self.doc.maintenance_status == 'Under AMC' and (not self.doc.amc_expiry_date or getdate(self.doc.amc_expiry_date) < datetime.date.today())):
-			msgprint("AMC expiry date and maintenance status mismatch. Please verify", raise_exception=1)
+			webnotes.throw(self.doc.name + ": " + 
+				_("AMC expiry date and maintenance status mismatched"))
 
 	def validate_warranty_status(self):
-		"""
-			validate warranty status	
-		"""
 		if (self.doc.maintenance_status == 'Out of Warranty' and self.doc.warranty_expiry_date and getdate(self.doc.warranty_expiry_date) >= datetime.date.today()) or (self.doc.maintenance_status == 'Under Warranty' and (not self.doc.warranty_expiry_date or getdate(self.doc.warranty_expiry_date) < datetime.date.today())):
-			msgprint("Warranty expiry date and maintenance status mismatch. Please verify", 
-				raise_exception=1)
+			webnotes.throw(self.doc.name + ": " + 
+				_("Warranty expiry date and maintenance status mismatched"))
 
 
 	def validate_warehouse(self):