Sfoglia il codice sorgente

feat: Allow showing currency symbol to the right

version-14
Ankush Menat 2 anni fa
parent
commit
054ad9c30c
4 ha cambiato i file con 34 aggiunte e 9 eliminazioni
  1. +10
    -1
      frappe/geo/doctype/currency/currency.json
  2. +13
    -7
      frappe/public/js/frappe/utils/number_format.js
  3. +5
    -0
      frappe/tests/test_fmt_money.py
  4. +6
    -1
      frappe/utils/data.py

+ 10
- 1
frappe/geo/doctype/currency/currency.json Vedi File

@@ -15,6 +15,7 @@
"fraction_units",
"smallest_currency_fraction_value",
"symbol",
"symbol_on_right",
"number_format"
],
"fields": [
@@ -69,16 +70,23 @@
"in_list_view": 1,
"label": "Number Format",
"options": "\n#,###.##\n#.###,##\n# ###.##\n# ###,##\n#'###.##\n#, ###.##\n#,##,###.##\n#,###.###\n#.###\n#,###"
},
{
"default": "0",
"fieldname": "symbol_on_right",
"fieldtype": "Check",
"label": "Show Currency Symbol on Right Side"
}
],
"icon": "fa fa-bitcoin",
"idx": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2020-10-29 06:33:12.879978",
"modified": "2022-07-04 09:42:52.425440",
"modified_by": "Administrator",
"module": "Geo",
"name": "Currency",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
@@ -109,5 +117,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

+ 13
- 7
frappe/public/js/frappe/utils/number_format.js Vedi File

@@ -122,16 +122,22 @@ window.format_number = function (v, format, decimals) {
};

function format_currency(v, currency, decimals) {
var format = get_number_format(currency);
var symbol = get_currency_symbol(currency);
if(decimals === undefined) {
const format = get_number_format(currency);
const symbol = get_currency_symbol(currency);
const show_symbol_on_right = frappe.model.get_value(":Currency", currency, "symbol_on_right") ?? false;

if (decimals === undefined) {
decimals = frappe.boot.sysdefaults.currency_precision || null;
}

if (symbol)
if (symbol) {
if (show_symbol_on_right) {
return format_number(v, format, decimals) + " " + __(symbol);
}
return __(symbol) + " " + format_number(v, format, decimals);
else
return format_number(v, format, decimals);
}

return format_number(v, format, decimals);
}

function get_currency_symbol(currency) {
@@ -249,4 +255,4 @@ Object.assign(window, {
remainder,
round_based_on_smallest_currency_fraction,
in_list
});
});

+ 5
- 0
frappe/tests/test_fmt_money.py Vedi File

@@ -97,6 +97,11 @@ class TestFmtMoney(unittest.TestCase):
self.assertEqual(fmt_money(100000, format="#,###.##"), "100,000.00")
self.assertEqual(fmt_money(None, format="#,###.##"), "0.00")

def test_fmt_with_symbol_pos(self):
frappe.db.set_value("Currency", "JPY", "symbol_on_right", 1)
self.assertEqual(fmt_money(100.0, format="#,###.##", currency="JPY"), "100.00 ¥")
self.assertEqual(fmt_money(100.0, format="#,###.##", currency="USD"), "$ 100.00")


if __name__ == "__main__":
frappe.connect()


+ 6
- 1
frappe/utils/data.py Vedi File

@@ -1187,7 +1187,12 @@ def fmt_money(

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 = frappe._(symbol) + " " + amount
symbol_on_right = frappe.db.get_value("Currency", currency, "symbol_on_right", cache=True)

if symbol_on_right:
amount = f"{amount} {frappe._(symbol)}"
else:
amount = f"{frappe._(symbol)} {amount}"

return amount



Caricamento…
Annulla
Salva