From 0891a69bdaeb4e0db781e0623141fa37783831fd Mon Sep 17 00:00:00 2001 From: Hussain Nagaria <34810212+NagariaHussain@users.noreply.github.com> Date: Tue, 2 Dec 2025 12:46:17 +0530 Subject: [PATCH] fix: bring back currency precision fix #34886 (#35015) * fix: use number format from currency if defined * refactor: extract out function --- frappe/model/meta.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/frappe/model/meta.py b/frappe/model/meta.py index 8167bd145d..15379ac2fd 100644 --- a/frappe/model/meta.py +++ b/frappe/model/meta.py @@ -892,22 +892,32 @@ def get_field_currency(df, doc=None): def get_field_precision(df, doc=None, currency=None): """get precision based on DocField options and fieldvalue in doc""" - from frappe.locale import get_number_format - if df.precision: precision = cint(df.precision) elif df.fieldtype == "Currency": precision = cint(frappe.db.get_default("currency_precision")) if not precision: - number_format = get_number_format() - precision = number_format.precision + precision = get_precision_from_currency_format(currency or get_field_currency(df, doc)) else: precision = cint(frappe.db.get_default("float_precision")) or 3 return precision +def get_precision_from_currency_format(currency: str) -> int: + """Get precision from currency format string if applicable.""" + from frappe.locale import get_number_format + from frappe.utils.number_format import NumberFormat + + use_format_from_currency = frappe.get_system_settings("use_number_format_from_currency") + number_format = get_number_format() + if use_format_from_currency: + currency_format = frappe.db.get_value("Currency", currency, "number_format", cache=True) + number_format = NumberFormat.from_string(currency_format) if currency_format else number_format + return number_format.precision + + def get_default_df(fieldname): if fieldname in (default_fields + child_table_fields): if fieldname in ("creation", "modified"):