Setup Wizard: on country select, change date format, save logo in Website Settings > Brand HTML

This commit is contained in:
Anand Doshi 2014-04-22 16:25:58 +05:30
parent 07339fc69e
commit 2944f49974
2 changed files with 51 additions and 37 deletions

View File

@ -83,6 +83,7 @@ frappe.pages['setup-wizard'].onload = function(wrapper) {
}); });
} }
}, },
{ {
title: __("The First User: You"), title: __("The First User: You"),
icon: "icon-user", icon: "icon-user",
@ -119,40 +120,6 @@ frappe.pages['setup-wizard'].onload = function(wrapper) {
} }
}, },
// Organization
{
title: __("The Organization"),
icon: "icon-building",
fields: [
{fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
placeholder: __('e.g. "My Company LLC"')},
{fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
placeholder: __('e.g. "MC"'),reqd:1},
{fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
description: __('Your financial year begins on'), reqd:1},
{fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
description: __('Your financial year ends on'), reqd:1},
{fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
placeholder:__('e.g. "Build tools for builders"'), reqd:1},
],
help: __('The name of your company for which you are setting up this system.'),
onload: function(slide) {
slide.get_input("company_name").on("change", function() {
var parts = slide.get_input("company_name").val().split(" ");
var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
slide.get_input("company_abbr").val(abbr.toUpperCase());
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
slide.get_input("fy_start_date").on("change", function() {
var year_end_date =
frappe.datetime.add_days(frappe.datetime.add_months(
frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
});
}
},
// Country // Country
{ {
title: __("Country, Timezone and Currency"), title: __("Country, Timezone and Currency"),
@ -197,6 +164,10 @@ frappe.pages['setup-wizard'].onload = function(wrapper) {
// add all timezones at the end, so that user has the option to change it to any timezone // add all timezones at the end, so that user has the option to change it to any timezone
$timezone.add_options([""].concat(frappe.all_timezones)); $timezone.add_options([""].concat(frappe.all_timezones));
// temporarily set date format
frappe.boot.sysdefaults.date_format = (frappe.country_info[country].date_format
|| "dd-mm-yyyy");
// get country specific chart of accounts // get country specific chart of accounts
// frappe.call({ // frappe.call({
// method: "erpnext.accounts.doctype.chart_of_accounts.chart_of_accounts.get_charts_for_country", // method: "erpnext.accounts.doctype.chart_of_accounts.chart_of_accounts.get_charts_for_country",
@ -211,6 +182,40 @@ frappe.pages['setup-wizard'].onload = function(wrapper) {
} }
}, },
// Organization
{
title: __("The Organization"),
icon: "icon-building",
fields: [
{fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
placeholder: __('e.g. "My Company LLC"')},
{fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
placeholder: __('e.g. "MC"'),reqd:1},
{fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
description: __('Your financial year begins on'), reqd:1},
{fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
description: __('Your financial year ends on'), reqd:1},
{fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
placeholder:__('e.g. "Build tools for builders"'), reqd:1},
],
help: __('The name of your company for which you are setting up this system.'),
onload: function(slide) {
slide.get_input("company_name").on("change", function() {
var parts = slide.get_input("company_name").val().split(" ");
var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
slide.get_input("company_abbr").val(abbr.toUpperCase());
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
slide.get_input("fy_start_date").on("change", function() {
var year_end_date =
frappe.datetime.add_days(frappe.datetime.add_months(
frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
});
}
},
// Logo // Logo
{ {
icon: "icon-bookmark", icon: "icon-bookmark",
@ -233,7 +238,7 @@ frappe.pages['setup-wizard'].onload = function(wrapper) {
slide.fields = slide.fields.concat([ slide.fields = slide.fields.concat([
{fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i, placeholder:__("e.g. VAT")}, {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i, placeholder:__("e.g. VAT")},
{fieldtype:"Column Break"}, {fieldtype:"Column Break"},
{fieldtype:"Data", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")}, {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
{fieldtype:"Section Break"}, {fieldtype:"Section Break"},
]); ]);
} }

View File

@ -68,6 +68,7 @@ def setup_account(args=None):
frappe.db.set_default('desktop:home_page', 'desktop') frappe.db.set_default('desktop:home_page', 'desktop')
website_maker(args.company_name, args.company_tagline, args.name) website_maker(args.company_name, args.company_tagline, args.name)
create_logo(args)
frappe.clear_cache() frappe.clear_cache()
frappe.db.commit() frappe.db.commit()
@ -98,7 +99,7 @@ def update_user_name(args):
if args.get("attach_user"): if args.get("attach_user"):
filename, filetype, content = args.get("attach_user").split(",") filename, filetype, content = args.get("attach_user").split(",")
fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_name fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
frappe.db.set_value("User", args.get("name"), "user_image", fileurl) frappe.db.set_value("User", args.get("name"), "user_image", fileurl)
add_all_roles_to(args.get("name")) add_all_roles_to(args.get("name"))
@ -370,9 +371,17 @@ def create_letter_head(args):
}).insert() }).insert()
filename, filetype, content = args.get("attach_letterhead").split(",") filename, filetype, content = args.get("attach_letterhead").split(",")
fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_name fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_url
frappe.db.set_value("Letter Head", _("Standard"), "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl) frappe.db.set_value("Letter Head", _("Standard"), "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl)
def create_logo(args):
if args.get("attach_logo"):
filename, filetype, content = args.get("attach_logo").split(",")
fileurl = save_file(filename, content, "Website Settings", "Website Settings",
decode=True).file_url
frappe.db.set_value("Website Settings", "Website Settings", "banner_html",
"<img src='%s' style='max-width: 100%%;'>" % fileurl)
def add_all_roles_to(name): def add_all_roles_to(name):
user = frappe.get_doc("User", name) user = frappe.get_doc("User", name)
for role in frappe.db.sql("""select name from tabRole"""): for role in frappe.db.sql("""select name from tabRole"""):