From b558ff68b91467546b0208ad6101ed247ea90b4c Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 23 Oct 2013 20:09:08 +0530 Subject: [PATCH 1/3] [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() From 3d0af67799c5bd4a6efc05465061695b3ceda455 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 24 Oct 2013 12:37:43 +0530 Subject: [PATCH 2/3] [fix] [minor] add time zone and country to global defaults --- ...pdate_control_panel_and_global_defaults.py | 12 +++------ patches/patch_list.py | 1 + .../global_defaults/global_defaults.js | 26 ++++++++++--------- .../global_defaults/global_defaults.py | 8 +++--- 4 files changed, 24 insertions(+), 23 deletions(-) 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 index dd5a1c1b73..7f40fb4091 100644 --- a/patches/october_2013/p06_update_control_panel_and_global_defaults.py +++ b/patches/october_2013/p06_update_control_panel_and_global_defaults.py @@ -8,15 +8,11 @@ def execute(): webnotes.reload_doc("setup", "doctype", "global_defaults") country = webnotes.conn.sql("""select value from `tabSingles` where - field ='country' and doctype='Control Panel'""") + 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() + field='timezone' and doctype='Control Panel'""") gb_bean = webnotes.bean("Global Defaults") - gb_bean.country = country - gb_bean.time_zone = time_zone + 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() \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 565ff9915f..37220abe1f 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -227,4 +227,5 @@ patch_list = [ "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 a4bdb48f4d..15350b7be5 100644 --- a/setup/doctype/global_defaults/global_defaults.js +++ b/setup/doctype/global_defaults/global_defaults.js @@ -2,24 +2,27 @@ // License: GNU General Public License v3. See license.txt $.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() { + onload: function(doc) { var me = this; + this.time_zone = 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(); + me.set_timezone_options(); + cur_frm.set_value("time_zone", me.time_zone); } }); }, + 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 = []; @@ -36,9 +39,8 @@ $.extend(cur_frm.cscript, { 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"); + + 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 4a3791bac3..3e06ff9359 100644 --- a/setup/doctype/global_defaults/global_defaults.py +++ b/setup/doctype/global_defaults/global_defaults.py @@ -61,9 +61,11 @@ class DocType: 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 + 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.save() - + def get_defaults(self): return webnotes.defaults.get_defaults() From b9bca26671b76035b5bce91be6dea2a07355cd42 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 24 Oct 2013 12:52:23 +0530 Subject: [PATCH 3/3] [fix] [minor] time zone fix --- setup/doctype/global_defaults/global_defaults.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup/doctype/global_defaults/global_defaults.js b/setup/doctype/global_defaults/global_defaults.js index 15350b7be5..8856acbb19 100644 --- a/setup/doctype/global_defaults/global_defaults.js +++ b/setup/doctype/global_defaults/global_defaults.js @@ -4,7 +4,7 @@ $.extend(cur_frm.cscript, { onload: function(doc) { var me = this; - this.time_zone = doc.time_zone; + this.timezone = doc.time_zone; wn.call({ method:"webnotes.country_info.get_country_timezone_info", @@ -12,7 +12,7 @@ $.extend(cur_frm.cscript, { 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.time_zone); + cur_frm.set_value("time_zone", me.timezone); } }); }, @@ -36,10 +36,11 @@ $.extend(cur_frm.cscript, { }, 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")); }