From 65c5bea720caee0d09801d8f3d0e0e3ba1d3d0f1 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 17 Dec 2014 13:07:31 +0530 Subject: [PATCH 1/3] Show a better error message in case of jinja syntax error --- frappe/core/doctype/print_format/print_format.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/print_format/print_format.py b/frappe/core/doctype/print_format/print_format.py index 4d414c50e5..4de0b05d33 100644 --- a/frappe/core/doctype/print_format/print_format.py +++ b/frappe/core/doctype/print_format/print_format.py @@ -20,7 +20,8 @@ class PrintFormat(Document): jenv = frappe.get_jenv() try: jenv.from_string(self.html) - except TemplateSyntaxError: + except TemplateSyntaxError, e: + frappe.msgprint('Line {}: {}'.format(e.lineno, e.message)) frappe.throw(frappe._("Syntax error in Jinja template")) def on_update(self): From 89f5c19cba4d25dfbda4b87c9a797075956287e7 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 17 Dec 2014 18:42:18 +0530 Subject: [PATCH 2/3] [fix] ability to parse number format # ###,## with appropriate rounding --- frappe/public/js/frappe/form/control.js | 31 ++++++++++++++----- frappe/public/js/frappe/misc/number_format.js | 16 +++++----- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/frappe/public/js/frappe/form/control.js b/frappe/public/js/frappe/form/control.js index b2c76fdf20..70bac486eb 100644 --- a/frappe/public/js/frappe/form/control.js +++ b/frappe/public/js/frappe/form/control.js @@ -387,29 +387,44 @@ frappe.ui.form.ControlInt = frappe.ui.form.ControlData.extend({ frappe.ui.form.ControlFloat = frappe.ui.form.ControlInt.extend({ parse: function(value) { - return isNaN(parseFloat(value)) ? null : flt(value); + return isNaN(parseFloat(value)) ? null : flt(value, this.get_precision()); }, + format_for_input: function(value) { var number_format; - var precision = this.df.precision || cint(frappe.boot.sysdefaults.float_precision, null); if (this.df.fieldtype==="Float" && this.df.options && this.df.options.trim()) { - number_format = get_number_format(this.get_currency()); + number_format = this.get_number_format(); } - var formatted_value = format_number(parseFloat(value), number_format, precision); + var formatted_value = format_number(parseFloat(value), number_format, this.get_precision()); return isNaN(parseFloat(value)) ? "" : formatted_value; }, // even a float field can be formatted based on currency format instead of float format - get_currency: function() { - return frappe.meta.get_field_currency(this.df, this.get_doc()); + get_number_format: function() { + var currency = frappe.meta.get_field_currency(this.df, this.get_doc()); + return get_number_format(currency); + }, + + get_precision: function() { + // round based on field precision or float precision, else don't round + return this.df.precision || cint(frappe.boot.sysdefaults.float_precision, null); } }); frappe.ui.form.ControlCurrency = frappe.ui.form.ControlFloat.extend({ format_for_input: function(value) { - var formatted_value = format_number(parseFloat(value), - get_number_format(this.get_currency()), this.df.precision || null); + var formatted_value = format_number(parseFloat(value), this.get_number_format(), this.get_precision()); return isNaN(parseFloat(value)) ? "" : formatted_value; + }, + + get_precision: function() { + // always round based on field precision or currency's precision + // this method is also called in this.parse() + if (!this.df.precision) { + this.df.precision = get_number_format_info(this.get_number_format()).precision; + } + + return this.df.precision; } }); diff --git a/frappe/public/js/frappe/misc/number_format.js b/frappe/public/js/frappe/misc/number_format.js index 0fba7e1017..86d61fd7b9 100644 --- a/frappe/public/js/frappe/misc/number_format.js +++ b/frappe/public/js/frappe/misc/number_format.js @@ -11,7 +11,8 @@ function flt(v, decimals, number_format) { // strip currency symbol if exists if(v.indexOf(" ")!=-1) { - v = v.split(" ")[1]; + // using slice(1).join(" ") because space could also be a group separator + v = isNaN(parseFloat(v.split(" ")[0])) ? v.split(" ").slice(1).join(" ") : v; } v = strip_number_groups(v, number_format); @@ -40,15 +41,16 @@ function cint(v, def) { function strip_number_groups(v, number_format) { if(!number_format) number_format = get_number_format(); + var info = get_number_format_info(number_format); // strip groups (,) - if(get_number_format_info(number_format).group_sep==".") { - v = v.replace(/\./g,''); + var group_regex = new RegExp(info.group_sep==="." ? "\\." : info.group_sep, "g"); + v = v.replace(group_regex, ""); - // sanitize decimal separator to . - v = v.replace(/,/g, "."); - } else { - v=v.replace(/,/g,''); + // replace decimal separator with (.) + if (info.decimal_str!=="." && info.decimal_str!=="") { + var decimal_regex = new RegExp(info.decimal_str, "g"); + v = v.replace(decimal_regex, "."); } return v; From ad1fd7fb9a6809cc5dfc839889d0a5acf1674c15 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Fri, 19 Dec 2014 18:41:06 +0600 Subject: [PATCH 3/3] bumped to version 4.9.0 --- frappe/__version__.py | 2 +- frappe/hooks.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/__version__.py b/frappe/__version__.py index ea674c5c54..454a2edae2 100644 --- a/frappe/__version__.py +++ b/frappe/__version__.py @@ -1 +1 @@ -__version__ = "4.8.0" +__version__ = "4.9.0" diff --git a/frappe/hooks.py b/frappe/hooks.py index f080427d1c..9e16230a9e 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -3,7 +3,7 @@ app_title = "Frappe Framework" app_publisher = "Web Notes Technologies Pvt. Ltd." app_description = "Full Stack Web Application Framework in Python" app_icon = "assets/frappe/images/frappe.svg" -app_version = "4.8.0" +app_version = "4.9.0" app_color = "#3498db" app_email = "support@frappe.io" diff --git a/setup.py b/setup.py index fcec2f4173..2d5d95459e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import os -version = "4.8.0" +version = "4.9.0" with open("requirements.txt", "r") as f: install_requires = f.readlines()