Print format currency utils

Hi guys,

So in print format you can do doc.get_formatted('currency_field') to format a Currency field, but if it’s calculated on the fly (in the template) then you can’t.

Although it’s possible to use frappe.format_value but it requires a field to exist for this. So in the end, the function is practically useless because I will still need to go to create a calculated field in the model to get the correct format.

I think, frappe.format_value should be more generic to take any value and just format it (just specify a type like ‘curreny’, ‘decimal’, etc.). Do you think so as well ?

This should work:

frappe.format_value(val, {"fieldtype":"Currency"});
3 Likes

I love to say it work but it doesn’t. Simply because we use Object not dict in the function:

File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/formatters.py", line 10, in format_value
    if df.fieldtype=="Date":
 AttributeError: 'dict' object has no attribute 'fieldtype'

Can you send a PR to use df.get("fieldname") in format value ? or set

df = frappe._dict(df) in the first line

Here you go: Convert dict to object before formatting by nathando · Pull Request #891 · frappe/frappe · GitHub