added number format # ###,## fixes frappe/erpnext#1641

This commit is contained in:
Rushabh Mehta 2014-05-27 16:00:17 +05:30
parent f27fa57cbc
commit 233ebf5e26
2 changed files with 38 additions and 284 deletions

View file

@ -1,339 +1,92 @@
{
"_last_update": null,
"_user_tags": null,
"allow_attach": null,
"allow_copy": null,
"allow_email": null,
"allow_import": null,
"allow_print": null,
"allow_rename": null,
"allow_trash": null,
"autoname": null,
"change_log": null,
"client_script": null,
"client_script_core": null,
"client_string": null,
"colour": null,
"creation": "2014-04-17 16:53:52.640856",
"custom": null,
"default_print_format": null,
"description": null,
"docstatus": 0,
"doctype": "DocType",
"document_type": "System",
"dt_template": null,
"fields": [
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "localization",
"fieldtype": "Section Break",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Localization",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": null,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"permlevel": 0
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "language",
"fieldtype": "Select",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": 1,
"label": "Language",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": "Loading...",
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": 1,
"search_index": 0,
"set_only_once": null,
"trigger": null,
"width": null
"search_index": 0
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "time_zone",
"fieldtype": "Select",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Time Zone",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": 1,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"reqd": 1
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "date_and_number_format",
"fieldtype": "Section Break",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Date and Number Format",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": null,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"permlevel": 0
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "date_format",
"fieldtype": "Select",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Date Format",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": "yyyy-mm-dd\ndd-mm-yyyy\ndd/mm/yyyy\nmm/dd/yyyy\nmm-dd-yyyy",
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": 1,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"reqd": 1
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "number_format",
"fieldtype": "Select",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Number Format",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": "#,###.##\n#.###,##\n# ###.##\n#,###.###\n#,##,###.##\n#.###\n#,###",
"options": "#,###.##\n#.###,##\n# ###.##\n# ###,##\n#,###.###\n#,##,###.##\n#.###\n#,###",
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": 1,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"reqd": 1
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "float_precision",
"fieldtype": "Select",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Float Precision",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": "\n2\n3\n4\n5\n6",
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": null,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"permlevel": 0
},
{
"allow_on_submit": null,
"default": null,
"depends_on": null,
"description": null,
"fieldname": "security",
"fieldtype": "Section Break",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Security",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": null,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"permlevel": 0
},
{
"allow_on_submit": null,
"default": "06:00",
"depends_on": null,
"description": "Session Expiry in Hours e.g. 06:00",
"fieldname": "session_expiry",
"fieldtype": "Data",
"hidden": null,
"ignore_restrictions": null,
"in_filter": null,
"in_list_view": null,
"label": "Session Expiry",
"no_column": null,
"no_copy": null,
"oldfieldname": null,
"oldfieldtype": null,
"options": "",
"permlevel": 0,
"print_hide": null,
"print_width": null,
"read_only": null,
"report_hide": null,
"reqd": null,
"search_index": null,
"set_only_once": null,
"trigger": null,
"width": null
"permlevel": 0
}
],
"hide_heading": null,
"hide_toolbar": null,
"icon": "icon-cog",
"idx": null,
"in_create": null,
"in_dialog": null,
"is_submittable": null,
"is_transaction_doc": null,
"issingle": 1,
"istable": null,
"max_attachments": null,
"menu_index": null,
"modified": "2014-04-17 17:52:27.046530",
"modified": "2014-05-27 06:29:28.922976",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",
"name_case": "",
"owner": "Administrator",
"parent": null,
"parent_node": null,
"parentfield": null,
"parenttype": null,
"permissions": [
{
"amend": null,
"cancel": null,
"create": 1,
"delete": null,
"email": null,
"export": null,
"import": null,
"match": null,
"permlevel": 0,
"print": null,
"read": 1,
"report": null,
"restrict": null,
"restricted": null,
"role": "System Manager",
"submit": null,
"write": 1
}
],
"plugin": null,
"print_outline": null,
"read_only": null,
"read_only_onload": null,
"search_fields": null,
"section_style": null,
"server_code": null,
"server_code_compiled": null,
"server_code_core": null,
"server_code_error": null,
"show_in_menu": null,
"smallicon": null,
"subject": null,
"tag_fields": null,
"title_field": null,
"use_template": null,
"version": null
]
}

View file

@ -3,9 +3,9 @@
if(!window.frappe) window.frappe = {};
function flt(v, decimals, number_format) {
function flt(v, decimals, number_format) {
if(v==null || v=='')return 0;
if(typeof v!=="number") {
v = v + "";
@ -20,27 +20,27 @@ function flt(v, decimals, number_format) {
if(isNaN(v))
v=0;
}
if(decimals!=null)
return _round(v, decimals);
return v;
}
function cint(v, def) {
if(v===true)
function cint(v, def) {
if(v===true)
return 1;
if(v===false)
return 0;
v=v+'';
if(v!=="0")v=lstrip(v, ['0']);
v=parseInt(v);
if(v!=="0")v=lstrip(v, ['0']);
v=parseInt(v);
if(isNaN(v))v=def===undefined?0:def;
return v;
return v;
}
function strip_number_groups(v, number_format) {
if(!number_format) number_format = get_number_format();
// strip groups (,)
if(get_number_format_info(number_format).group_sep==".") {
v = v.replace(/\./g,'');
@ -50,7 +50,7 @@ function strip_number_groups(v, number_format) {
} else {
v=v.replace(/,/g,'');
}
return v;
}
@ -59,32 +59,33 @@ frappe.number_format_info = {
"#,###.##": {decimal_str:".", group_sep:",", precision:2},
"#.###,##": {decimal_str:",", group_sep:".", precision:2},
"# ###.##": {decimal_str:".", group_sep:" ", precision:2},
"# ###,##": {decimal_str:",", group_sep:" ", precision:2},
"#,###.###": {decimal_str:".", group_sep:",", precision:3},
"#,##,###.##": {decimal_str:".", group_sep:",", precision:2},
"#.###": {decimal_str:"", group_sep:".", precision:0},
"#,###": {decimal_str:"", group_sep:",", precision:0},
}
window.format_number = function(v, format, decimals){
window.format_number = function(v, format, decimals){
if (!format) {
format = get_number_format();
if(decimals == null) decimals = cint(frappe.defaults.get_default("float_precision")) || 3;
}
info = get_number_format_info(format);
//Fix the decimal first, toFixed will auto fill trailing zero.
decimals = decimals || info.precision;
v = flt(v, decimals, format);
if(v<0) var is_negative = true;
if(v<0) var is_negative = true;
v = Math.abs(v);
v = v.toFixed(decimals);
var part = v.split('.');
// get group position and parts
var group_position = info.group_sep ? 3 : 0;
@ -92,14 +93,14 @@ window.format_number = function(v, format, decimals){
var integer = part[0];
var str = '';
var offset = integer.length % group_position;
for (var i=integer.length; i>=0; i--) {
for (var i=integer.length; i>=0; i--) {
var l = replace_all(str, info.group_sep, "").length;
if(format=="#,##,###.##" && str.indexOf(",")!=-1) { // INR
group_position = 2;
l += 1;
}
str += integer.charAt(i);
str += integer.charAt(i);
if (l && !((l+1) % group_position) && i!=0 ) {
str += info.group_sep;
@ -110,10 +111,10 @@ window.format_number = function(v, format, decimals){
if(part[0]+""=="") {
part[0]="0";
}
// join decimal
part[1] = part[1] ? (info.decimal_str + part[1]) : "";
// join
return (is_negative ? "-" : "") + part[0] + part[1];
};
@ -150,13 +151,13 @@ function get_number_format(currency) {
|| frappe.model.get_value("Currency", frappe.boot.sysdefaults.currency, "number_format")
|| "#,###.##";
}
var number_format;
if(currency && frappe.boot) {
number_format = frappe.model.get_value("Currency", currency,
number_format = frappe.model.get_value("Currency", currency,
"number_format");
}
return number_format || global_number_format;
}
@ -205,4 +206,4 @@ function in_list(list, item) {
for(var i=0, j=list.length; i<j; i++)
if(list[i]==item) return true;
return false;
}
}