From 2baa15d4a2bd275df574b087e065fac2e2433a66 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 31 May 2013 14:30:21 +0530 Subject: [PATCH] [precision and currency] [fix] fix in get precision and display of currency --- public/js/wn/misc/number_format.js | 3 ++- public/js/wn/model/meta.js | 2 +- webnotes/model/meta.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/public/js/wn/misc/number_format.js b/public/js/wn/misc/number_format.js index 044f7bc95b..1d9fa1aae3 100644 --- a/public/js/wn/misc/number_format.js +++ b/public/js/wn/misc/number_format.js @@ -120,7 +120,7 @@ function get_currency_symbol(currency) { if(!currency) currency = wn.boot.sysdefaults.currency; - return wn.model.get_value("Currency", currency, "symbol") || currency; + return wn.model.get_value(":Currency", currency, "symbol") || currency; } else { // load in template return wn.currency_symbols[currency]; @@ -161,5 +161,6 @@ function roundNumber(num, dec) { function precision(fieldname, doc) { if(!doc) doc = cur_frm.doc; var df = wn.meta.get_docfield(doc.doctype, fieldname, doc.parent || doc.name); + if(!df) console.log(fieldname + ": could not find docfield in method precision()"); return wn.meta.get_field_precision(df, doc); } \ No newline at end of file diff --git a/public/js/wn/model/meta.js b/public/js/wn/model/meta.js index e3211fcab7..656bb139da 100644 --- a/public/js/wn/model/meta.js +++ b/public/js/wn/model/meta.js @@ -159,7 +159,7 @@ $.extend(wn.meta, { get_field_precision: function(df, doc) { var precision = wn.defaults.get_default("float_precision") || 6; - if(df.fieldtype === "Currency") { + 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); diff --git a/webnotes/model/meta.py b/webnotes/model/meta.py index ed4f43345d..143ce703ac 100644 --- a/webnotes/model/meta.py +++ b/webnotes/model/meta.py @@ -24,6 +24,7 @@ from __future__ import unicode_literals import webnotes +from webnotes.utils import cstr def get_dt_values(doctype, fields, as_dict = 0): return webnotes.conn.sql('SELECT %s FROM tabDocType WHERE name="%s"' % (fields, doctype), as_dict = as_dict) @@ -88,7 +89,7 @@ def get_field_currency(df, doc): """get currency based on DocField options and fieldvalue in doc""" currency = None - if ":" in df.options: + if ":" in cstr(df.options): split_opts = df.options.split(":") if len(split_opts)==3: currency = webnotes.conn.get_value(split_opts[0], doc.fields.get(split_opts[1]),