diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index 57b4777355..8fd64689fc 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -963,10 +963,13 @@ class BaseDocument(object): from frappe.model.meta import get_default_df df = get_default_df(fieldname) - if df.fieldtype == "Currency" and not currency: - currency = self.get(df.get("options")) - if not frappe.db.exists('Currency', currency, cache=True): - currency = None + if ( + df.fieldtype == "Currency" + and not currency + and (currency_field := df.get("options")) + and (currency_value := self.get(currency_field)) + ): + currency = frappe.db.get_value('Currency', currency_value, cache=True) val = self.get(fieldname) diff --git a/frappe/tests/test_document.py b/frappe/tests/test_document.py index 169d1ebb2c..5caccb167e 100644 --- a/frappe/tests/test_document.py +++ b/frappe/tests/test_document.py @@ -246,7 +246,7 @@ class TestDocument(unittest.TestCase): 'fields': [ {'label': 'Currency', 'fieldname': 'currency', 'reqd': 1, 'fieldtype': 'Currency'}, ] - }).insert() + }).insert(ignore_if_duplicate=True) frappe.delete_doc_if_exists("Currency", "INR", 1) @@ -262,6 +262,10 @@ class TestDocument(unittest.TestCase): }) self.assertEqual(d.get_formatted('currency', currency='INR', format="#,###.##"), '₹ 100,000.00') + # should work even if options aren't set in df + # and currency param is not passed + self.assertIn("0", d.get_formatted("currency")) + def test_limit_for_get(self): doc = frappe.get_doc("DocType", "DocType") # assuming DocType has more than 3 Data fields