Created
November 27, 2014 09:10
-
-
Save nathando/e94242454709cd73185f to your computer and use it in GitHub Desktop.
Inconsistency in get_field_precision logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_field_precision: function(df, doc) { | |
var precision = cint(frappe.defaults.get_default("float_precision")) || 3; | |
// Here if the precision exists, it should return directly, | |
// Therefore, it always can overwrite number format -> 5,6,7,8 ... | |
if (df && cint(df.precision)) { | |
precision = cint(df.precision); | |
} else if(df && df.fieldtype === "Currency") { | |
var currency = this.get_field_currency(df, doc); | |
var number_format = get_number_format(currency); | |
var number_format_info = get_number_format_info(number_format); | |
precision = number_format_info.precision; | |
} | |
return precision; | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_field_precision(df, doc): | |
"""get precision based on DocField options and fieldvalue in doc""" | |
from frappe.utils import get_number_format_info | |
# Here it does not return directly if found a precision. | |
# Precision end up being overwritten by number format ####.## -> 2 | |
precision = cint(df.precision) or cint(frappe.db.get_default("float_precision")) or 3 | |
if df.fieldtype == "Currency": | |
number_format = None | |
currency = get_field_currency(df, doc) | |
if not currency: | |
# use default currency | |
currency = frappe.db.get_default("currency") | |
if currency: | |
number_format = frappe.db.get_value("Currency", currency, "number_format") | |
if not number_format: | |
number_format = frappe.db.get_default("number_format") or "#,###.##" | |
decimal_str, comma_str, precision = get_number_format_info(number_format) | |
return precision |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment