[fix] added country and time zone to global defaults

This commit is contained in:
Akhilesh Darjee
2013-10-23 20:09:08 +05:30
parent 97e55710da
commit b558ff68b9
6 changed files with 90 additions and 14 deletions

View File

@@ -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;
});
}
$.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");
}
});

View File

@@ -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()

View File

@@ -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"
}

View File

@@ -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()