Merge pull request #1000 from akhileshdarjee/master

[fix] added country and time zone to global defaults
This commit is contained in:
Nabin Hait 2013-10-24 01:58:33 -07:00
commit dc08fdfc99
7 changed files with 92 additions and 14 deletions

View File

@ -0,0 +1,18 @@
# 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'""")
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()

View File

@ -227,4 +227,5 @@ patch_list = [
"patches.october_2013.p03_remove_sales_and_purchase_return_tool", "patches.october_2013.p03_remove_sales_and_purchase_return_tool",
"patches.october_2013.p04_update_report_permission", "patches.october_2013.p04_update_report_permission",
"patches.october_2013.p05_delete_gl_entries_for_cancelled_vouchers", "patches.october_2013.p05_delete_gl_entries_for_cancelled_vouchers",
"patches.october_2013.p06_update_control_panel_and_global_defaults",
] ]

View File

@ -28,7 +28,7 @@ $.extend(erpnext.complete_setup, {
options: "", fieldtype: 'Select'}, options: "", fieldtype: 'Select'},
{fieldname:'currency', label: 'Default Currency', reqd:1, {fieldname:'currency', label: 'Default Currency', reqd:1,
options: "", fieldtype: 'Select'}, options: "", fieldtype: 'Select'},
{fieldname:'timezone', label: 'Time Zone', reqd:1, {fieldname:'time_zone', label: 'Time Zone', reqd:1,
options: "", fieldtype: 'Select'}, options: "", fieldtype: 'Select'},
{fieldname:'industry', label: 'Industry', reqd:1, {fieldname:'industry', label: 'Industry', reqd:1,
options: erpnext.complete_setup.domains.join('\n'), fieldtype: 'Select'}, options: erpnext.complete_setup.domains.join('\n'), fieldtype: 'Select'},
@ -51,10 +51,10 @@ $.extend(erpnext.complete_setup, {
d.get_input("currency").empty() d.get_input("currency").empty()
.add_options(wn.utils.unique([""].concat($.map(erpnext.country_info, .add_options(wn.utils.unique([""].concat($.map(erpnext.country_info,
function(opts, country) { return opts.currency; }))).sort()); function(opts, country) { return opts.currency; }))).sort());
d.get_input("timezone").empty() d.get_input("time_zone").empty()
.add_options([""].concat(erpnext.all_timezones)); .add_options([""].concat(erpnext.all_timezones));
} }
}) });
// on clicking update // on clicking update
d.fields_dict.update.input.onclick = function() { d.fields_dict.update.input.onclick = function() {
@ -84,7 +84,7 @@ $.extend(erpnext.complete_setup, {
d.fields_dict.country.input.onchange = function() { d.fields_dict.country.input.onchange = function() {
var country = d.fields_dict.country.input.value; 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(); $timezone.empty();
// add country specific timezones first // add country specific timezones first
if(country){ if(country){

View File

@ -1,9 +1,47 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Validate $.extend(cur_frm.cscript, {
cur_frm.cscript.validate = function(doc, cdt, cdn) { onload: function(doc) {
return $c_obj(make_doclist(cdt, cdn), 'get_defaults', '', function(r, rt){ var me = this;
sys_defaults = r.message; 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"));
}
});

View File

@ -29,6 +29,7 @@ class DocType:
def on_update(self): def on_update(self):
"""update defaults""" """update defaults"""
self.validate_session_expiry() self.validate_session_expiry()
self.update_control_panel()
for key in keydict: for key in keydict:
webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], '')) webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], ''))
@ -58,6 +59,13 @@ class DocType:
webnotes.msgprint("""Session Expiry must be in format hh:mm""", webnotes.msgprint("""Session Expiry must be in format hh:mm""",
raise_exception=1) 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.save()
def get_defaults(self): def get_defaults(self):
return webnotes.defaults.get_defaults() return webnotes.defaults.get_defaults()

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-02 17:53:24", "creation": "2013-05-02 17:53:24",
"docstatus": 0, "docstatus": 0,
"modified": "2013-10-23 10:22:44", "modified": "2013-10-23 18:06:04",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -153,6 +153,13 @@
"label": "Session Expiry", "label": "Session Expiry",
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "country",
"fieldtype": "Select",
"label": "Country",
"options": "link:Country"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "sms_sender_name", "fieldname": "sms_sender_name",
@ -175,6 +182,12 @@
"options": "Standard\nClassic\nModern\nSpartan", "options": "Standard\nClassic\nModern\nSpartan",
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "time_zone",
"fieldtype": "Select",
"label": "Time Zone"
},
{ {
"doctype": "DocPerm" "doctype": "DocPerm"
} }

View File

@ -141,7 +141,7 @@ class DocType:
# control panel # control panel
cp = webnotes.doc("Control Panel", "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.fields[k] = args[k]
cp.save() cp.save()