From b558ff68b91467546b0208ad6101ed247ea90b4c Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 23 Oct 2013 20:09:08 +0530 Subject: [PATCH] [fix] added country and time zone to global defaults --- ...pdate_control_panel_and_global_defaults.py | 22 +++++++++ public/js/complete_setup.js | 8 ++-- .../global_defaults/global_defaults.js | 47 ++++++++++++++++--- .../global_defaults/global_defaults.py | 10 +++- .../global_defaults/global_defaults.txt | 15 +++++- setup/doctype/setup_control/setup_control.py | 2 +- 6 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 patches/october_2013/p06_update_control_panel_and_global_defaults.py 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 0000000000..dd5a1c1b73 --- /dev/null +++ b/patches/october_2013/p06_update_control_panel_and_global_defaults.py @@ -0,0 +1,22 @@ +# 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'""") + + cp_bean = webnotes.bean("Control Panel") + cp_bean.time_zone = time_zone + cp_bean.save() + + gb_bean = webnotes.bean("Global Defaults") + gb_bean.country = country + gb_bean.time_zone = time_zone + gb_bean.save() \ No newline at end of file diff --git a/public/js/complete_setup.js b/public/js/complete_setup.js index e565621a2a..7448c7b364 100644 --- a/public/js/complete_setup.js +++ b/public/js/complete_setup.js @@ -28,7 +28,7 @@ $.extend(erpnext.complete_setup, { options: "", fieldtype: 'Select'}, {fieldname:'currency', label: 'Default Currency', reqd:1, options: "", fieldtype: 'Select'}, - {fieldname:'timezone', label: 'Time Zone', reqd:1, + {fieldname:'time_zone', label: 'Time Zone', reqd:1, options: "", fieldtype: 'Select'}, {fieldname:'industry', label: 'Industry', reqd:1, options: erpnext.complete_setup.domains.join('\n'), fieldtype: 'Select'}, @@ -51,10 +51,10 @@ $.extend(erpnext.complete_setup, { d.get_input("currency").empty() .add_options(wn.utils.unique([""].concat($.map(erpnext.country_info, function(opts, country) { return opts.currency; }))).sort()); - d.get_input("timezone").empty() + d.get_input("time_zone").empty() .add_options([""].concat(erpnext.all_timezones)); } - }) + }); // on clicking update d.fields_dict.update.input.onclick = function() { @@ -84,7 +84,7 @@ $.extend(erpnext.complete_setup, { d.fields_dict.country.input.onchange = function() { var country = d.fields_dict.country.input.value; - var $timezone = $(d.fields_dict.timezone.input); + var $timezone = $(d.fields_dict.time_zone.input); $timezone.empty(); // add country specific timezones first if(country){ diff --git a/setup/doctype/global_defaults/global_defaults.js b/setup/doctype/global_defaults/global_defaults.js index 39999795a1..a4bdb48f4d 100644 --- a/setup/doctype/global_defaults/global_defaults.js +++ b/setup/doctype/global_defaults/global_defaults.js @@ -1,9 +1,44 @@ // 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, { + validate: function(doc, cdt, cdn) { + return $c_obj(make_doclist(cdt, cdn), 'get_defaults', '', function(r, rt){ + sys_defaults = r.message; + }); + }, + + refresh: function() { + var me = this; + 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(); + } + }); + }, + + 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) { + if(!filtered_options) filtered_options = []; + var remaining_timezones = $.map(erpnext.all_timezones, function(v) + { return filtered_options.indexOf(v)===-1 ? v : null; }); + + this.frm.fields_dict.time_zone.df.options = + (filtered_options.concat([""]).concat(remaining_timezones)).join("\n"); + refresh_field("time_zone"); + } +}); \ 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 1b1d50c2ff..4a3791bac3 100644 --- a/setup/doctype/global_defaults/global_defaults.py +++ b/setup/doctype/global_defaults/global_defaults.py @@ -29,6 +29,7 @@ class DocType: 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,12 @@ class DocType: 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") + cp_bean.country = self.doc.country + cp_bean.time_zone = self.doc.time_zone + 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 a8a80b1045..da40a19ca3 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" }, @@ -153,6 +153,13 @@ "label": "Session Expiry", "read_only": 0 }, + { + "doctype": "DocField", + "fieldname": "country", + "fieldtype": "Select", + "label": "Country", + "options": "link:Country" + }, { "doctype": "DocField", "fieldname": "sms_sender_name", @@ -175,6 +182,12 @@ "options": "Standard\nClassic\nModern\nSpartan", "read_only": 0 }, + { + "doctype": "DocField", + "fieldname": "time_zone", + "fieldtype": "Select", + "label": "Time Zone" + }, { "doctype": "DocPerm" } diff --git a/setup/doctype/setup_control/setup_control.py b/setup/doctype/setup_control/setup_control.py index b78bfcc7d6..818e310425 100644 --- a/setup/doctype/setup_control/setup_control.py +++ b/setup/doctype/setup_control/setup_control.py @@ -141,7 +141,7 @@ class DocType: # control panel cp = webnotes.doc("Control Panel", "Control Panel") - for k in ['country', 'timezone', 'company_name']: + for k in ['country', 'time_zone', 'company_name']: cp.fields[k] = args[k] cp.save()