Exemplo n.º 1
0
def get_currency_precision():
    precision = cint(frappe.db.get_default("currency_precision"))
    if not precision:
        number_format = frappe.db.get_default("number_format") or "#,###.##"
        precision = get_number_format_info(number_format)[2]

    return precision
Exemplo n.º 2
0
def get_field_precision(df, doc=None, currency=None):
	"""get precision based on DocField options and fieldvalue in doc"""
	from frappe.utils import get_number_format_info

	if cint(df.precision):
		precision = cint(df.precision)

	elif df.fieldtype == "Currency":
		number_format = None
		if not currency and doc:
			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", cache=True)

		if not number_format:
			number_format = frappe.db.get_default("number_format") or "#,###.##"

		decimal_str, comma_str, precision = get_number_format_info(number_format)

	else:
		precision = cint(frappe.db.get_default("float_precision")) or 3

	return precision
Exemplo n.º 3
0
def get_field_precision(df, doc=None, currency=None):
    """get precision based on DocField options and fieldvalue in doc"""
    from frappe.utils import get_number_format_info

    if cint(df.precision):
        precision = cint(df.precision)

    elif df.fieldtype == "Currency":
        number_format = None
        if not currency and doc:
            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",
                                                cache=True)

        if not number_format:
            number_format = frappe.db.get_default(
                "number_format") or "#,###.##"

        decimal_str, comma_str, precision = get_number_format_info(
            number_format)

    else:
        precision = cint(frappe.db.get_default("float_precision")) or 3

    return precision
Exemplo n.º 4
0
def get_currency_precision():
	precision = cint(frappe.db.get_default("currency_precision"))
	if not precision:
		number_format = frappe.db.get_default("number_format") or "#,###.##"
		precision = get_number_format_info(number_format)[2]

	return precision
Exemplo n.º 5
0
def get_currency_precision(currency=None):
	if not currency:
		currency = frappe.db.get_value("Company",
			frappe.db.get_default("Company"), "default_currency", cache=True)
	currency_format = frappe.db.get_value("Currency", currency, "number_format", cache=True)

	from frappe.utils import get_number_format_info
	return get_number_format_info(currency_format)[2]
def execute():
    if not frappe.db.get_value("System Settings", None, "currency_precision"):
        default_currency = frappe.db.get_default("currency")
        number_format = frappe.db.get_value("Currency", default_currency, "number_format") \
         or frappe.db.get_default("number_format")
        if number_format:
            precision = get_number_format_info(number_format)[2]
        else:
            precision = 2

        ss = frappe.get_doc("System Settings")
        ss.currency_precision = precision
        ss.flags.ignore_mandatory = True
        ss.save()
def execute():
	frappe.reload_doc('core', 'doctype', 'system_settings', force=True)
	if not frappe.db.get_value("System Settings", None, "currency_precision"):
		default_currency = frappe.db.get_default("currency")
		number_format = frappe.db.get_value("Currency", default_currency, "number_format", cache=True) \
			or frappe.db.get_default("number_format")
		if number_format:
			precision = get_number_format_info(number_format)[2]
		else:
			precision = 2

		ss = frappe.get_doc("System Settings")
		ss.currency_precision = precision
		ss.flags.ignore_mandatory = True
		ss.save()
Exemplo n.º 8
0
def get_field_precision(df, doc=None, currency=None):
	"""get precision based on DocField options and fieldvalue in doc"""
	from frappe.utils import get_number_format_info

	if df.precision:
		precision = cint(df.precision)

	elif df.fieldtype == "Currency":
		precision = cint(frappe.db.get_default("currency_precision"))
		if not precision:
			number_format = frappe.db.get_default("number_format") or "#,###.##"
			decimal_str, comma_str, precision = get_number_format_info(number_format)
	else:
		precision = cint(frappe.db.get_default("float_precision")) or 3

	return precision
Exemplo n.º 9
0
def get_field_precision(df, doc=None, currency=None):
	"""get precision based on DocField options and fieldvalue in doc"""
	from frappe.utils import get_number_format_info

	if cint(df.precision):
		precision = cint(df.precision)

	elif df.fieldtype == "Currency":
		precision = cint(frappe.db.get_default("currency_precision"))
		if not precision:
			number_format = frappe.db.get_default("number_format") or "#,###.##"
			decimal_str, comma_str, precision = get_number_format_info(number_format)
	else:
		precision = cint(frappe.db.get_default("float_precision")) or 3

	return precision
Exemplo n.º 10
0
def get_field_precision(df, doc):
	"""get precision based on DocField options and fieldvalue in doc"""
	from frappe.utils import get_number_format_info

	number_format = None
	if df.fieldtype == "Currency":
		currency = get_field_currency(df, doc)
		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)

	if df.fieldtype == "Float":
		precision = cint(frappe.db.get_default("float_precision")) or 3

	return precision
Exemplo n.º 11
0
def get_field_precision(df, doc):
	"""get precision based on DocField options and fieldvalue in doc"""
	from frappe.utils import get_number_format_info

	number_format = None
	if df.fieldtype == "Currency":
		currency = get_field_currency(df, doc)
		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)

	if df.fieldtype == "Float":
		precision = cint(frappe.db.get_default("float_precision")) or 3

	return precision
Exemplo n.º 12
0
def cpce_number_format(doc,
                       amount,
                       precision=None,
                       currency=None,
                       noCurrency=None,
                       hideTrailingZero=None):
    """
	Convert to string with commas for thousands, millions etc
	"""
    number_format = doc.get("number_format") or "#,###.##"
    if noCurrency and number_format == "#.###":
        number_format = "#.###,##"
    if noCurrency and number_format == "#,###":
        number_format = "#,###.##"
    if precision is None:
        precision = cint(frappe.db.get_default('currency_precision')) or None

    decimal_str, comma_str, number_format_precision = get_number_format_info(
        number_format)

    if precision is None:
        precision = number_format_precision

    # 40,000 -> 40,000.00
    # 40,000.00000 -> 40,000.00
    # 40,000.23000 -> 40,000.23

    if isinstance(amount, string_types):
        amount = flt(amount, precision)

    if decimal_str:
        decimals_after = str(round(amount % 1, precision))
        parts = decimals_after.split('.')
        parts = parts[1] if len(parts) > 1 else parts[0]
        decimals = parts
        if precision > 2:
            if len(decimals) < 3:
                if currency:
                    fraction = frappe.db.get_value(
                        "Currency", currency, "fraction_units",
                        cache=True) or 100
                    precision = len(cstr(fraction)) - 1
                else:
                    precision = number_format_precision
            elif len(decimals) < precision:
                precision = len(decimals)

    amount = '%.*f' % (precision, round(flt(amount), precision))

    if amount.find('.') == -1:
        decimals = ''
    else:
        decimals = amount.split('.')[1]

    parts = []
    minus = ''
    if flt(amount) < 0:
        minus = '-'

    amount = cstr(abs(flt(amount))).split('.')[0]

    if len(amount) > 3:
        parts.append(amount[-3:])
        amount = amount[:-3]

        val = number_format == "#,##,###.##" and 2 or 3

        while len(amount) > val:
            parts.append(amount[-val:])
            amount = amount[:-val]

    parts.append(amount)

    parts.reverse()

    amount = comma_str.join(parts) + ((precision and decimal_str) and
                                      (decimal_str + decimals) or "")
    if amount != '0':
        amount = minus + amount

    if hideTrailingZero:
        amount = amount.strip("0").rstrip('.').rstrip(',')

    if currency and frappe.defaults.get_global_default(
            "hide_currency_symbol") != "Yes":
        symbol = frappe.db.get_value(
            "Currency", currency, "symbol", cache=True) or currency
        amount = symbol + " " + amount

    return amount