Allow overriding digits in Lang.currency and Report.format_currency
issue9588 review292221002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Allow overriding digits in Lang.currency and Report.format_currency
|
||||
* Add record name in report filename
|
||||
* Add deletable and writable state from ir.rule to read
|
||||
* Add language attribute to data tag
|
||||
|
||||
+4
-2
@@ -459,14 +459,16 @@ class Lang(DeactivableMixin, ModelSQL, ModelView):
|
||||
formatted = _strip_padding(formatted, seps)
|
||||
return formatted
|
||||
|
||||
def currency(self, val, currency, symbol=True, grouping=False):
|
||||
def currency(
|
||||
self, val, currency, symbol=True, grouping=False, digits=None):
|
||||
"""
|
||||
Formats val according to the currency settings in lang.
|
||||
"""
|
||||
# Code from currency in locale.py
|
||||
|
||||
# check for illegal values
|
||||
digits = currency.digits
|
||||
if digits is None:
|
||||
digits = currency.digits
|
||||
if digits == 127:
|
||||
raise ValueError("Currency formatting is not possible using "
|
||||
"the 'C' locale.")
|
||||
|
||||
@@ -383,13 +383,14 @@ class Report(URLMixin, PoolBase):
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def format_currency(cls, value, lang, currency, symbol=True,
|
||||
grouping=True):
|
||||
def format_currency(
|
||||
cls, value, lang, currency, symbol=True, grouping=True,
|
||||
digits=None):
|
||||
pool = Pool()
|
||||
Lang = pool.get('ir.lang')
|
||||
if lang is None:
|
||||
lang = Lang.get()
|
||||
return lang.currency(value, currency, symbol, grouping)
|
||||
return lang.currency(value, currency, symbol, grouping, digits=digits)
|
||||
|
||||
@classmethod
|
||||
def format_number(cls, value, lang, digits=2, grouping=True,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import datetime
|
||||
import unittest
|
||||
from unittest.mock import patch, ANY
|
||||
from decimal import Decimal
|
||||
from unittest.mock import Mock, patch, ANY
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from trytond.config import config
|
||||
from trytond.pool import Pool
|
||||
@@ -50,6 +52,24 @@ class IrTestCase(ModuleTestCase):
|
||||
Model = pool.get('ir.model')
|
||||
Model.global_search('User', 10)
|
||||
|
||||
@with_transaction()
|
||||
def test_lang_currency(self):
|
||||
"Test Lang.currency"
|
||||
pool = Pool()
|
||||
Lang = pool.get('ir.lang')
|
||||
lang = Lang.get('en')
|
||||
currency = Mock()
|
||||
currency.digits = 2
|
||||
currency.symbol = '$'
|
||||
test_data = [
|
||||
(Decimal('10.50'), True, False, None, '$10.50'),
|
||||
(Decimal('10.50'), True, False, 4, '$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"
|
||||
|
||||
Reference in New Issue
Block a user