Fallback to code to format currency without symbol

This commit is contained in:
Cédric Krier
2023-02-23 13:39:07 +01:00
parent 6be816d947
commit 39af6a02e3
3 changed files with 23 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Fallback to code to format currency without symbol
* Add sort method to order like ModelStorage.search
* Do not alter argument values of with_transaction decorator (#12108)
* Support SMALLINT and REAL as backend types
+3
View File
@@ -501,6 +501,9 @@ class Lang(DeactivableMixin, ModelSQL, ModelView):
or self.p_cs_precedes)
separated = (val < 0 and self.n_sep_by_space
or self.p_sep_by_space)
if not smb and hasattr(currency, 'code'):
smb = currency.code
separated = True
if precedes:
s = smb + (separated and ' ' or '') + s
+19
View File
@@ -142,6 +142,25 @@ class IrTestCase(ModuleTestCase):
lang.currency(value, currency, symbol, grouping, digits),
result)
@with_transaction()
def test_lang_currency_without_symbol(self):
"Test Lang.currency without symbol"
pool = Pool()
Lang = pool.get('ir.lang')
lang = Lang.get('en')
currency = Mock()
currency.digits = 2
currency.symbol = None
currency.code = 'USD'
test_data = [
(Decimal('10.50'), True, False, None, 'USD 10.50'),
(Decimal('10.50'), True, False, 4, 'USD 10.5000'),
]
for value, symbol, grouping, digits, result in test_data:
self.assertEqual(
lang.currency(value, currency, symbol, grouping, digits),
result)
@with_transaction()
def test_lang_format(self):
"Test Lang.format"