Enforce strictly positive rounding value for currency

Closes #13600
This commit is contained in:
Cédric Krier committed 2024-10-14 14:35:37 +02:00
1 parent 6d0270e7d8
commit 62fe5b3fdf
2 files changed
+3 -60

No files matched your search

+3
View File
@@ -56,6 +56,9 @@ class Currency(
help="Add floating exchange rates for the currency.")
rounding = fields.Numeric('Rounding factor', required=True,
digits=(12, Eval('digits', 6)),
domain=[
('rounding', '>', 0),
],
help="The minimum amount which can be represented in this currency.")
digits = fields.Integer("Digits", required=True,
help="The number of digits to display after the decimal separator.")
-60
View File
@@ -118,29 +118,6 @@ class CurrencyTestCase(ModuleTestCase):
self.assertEqual(rounded, Decimal('1E50'))
@with_transaction()
def test_round_negative(self):
"Test rounding with negative rounding"
cu = create_currency('cu')
cu.rounding = -Decimal('0.1')
cu.digits = 1
cu.save()
rounded = cu.round(Decimal('1.23'))
self.assertEqual(rounded, Decimal('1.2'))
@with_transaction()
def test_round_zero(self):
"Test rounding with 0 as rounding"
cu = create_currency('cu')
cu.rounding = Decimal('0')
cu.save()
rounded = cu.round(Decimal('1.2345'))
self.assertEqual(rounded, Decimal('1.2345'))
@with_transaction()
def test_round_opposite(self):
"Test the opposite rounding"
@@ -183,43 +160,6 @@ class CurrencyTestCase(ModuleTestCase):
with self.subTest(value=-value):
self.assertEqual(cu.is_zero(-value), result)
@with_transaction()
def test_is_zero_negative(self):
"Test is zero with negative rounding"
cu = create_currency('cu')
cu.rounding = Decimal('-0.001')
cu.digits = 3
cu.save()
for value, result in [
(Decimal('0'), True),
(Decimal('0.0002'), True),
(Decimal('0.0009'), False),
(Decimal('0.002'), False),
]:
with self.subTest(value=value):
self.assertEqual(cu.is_zero(value), result)
with self.subTest(value=-value):
self.assertEqual(cu.is_zero(-value), result)
@with_transaction()
def test_is_zero_zero(self):
"Test is zero with 0 as rounding"
cu = create_currency('cu')
cu.rounding = Decimal('0')
cu.save()
for value, result in [
(Decimal('0'), True),
(Decimal('0.0002'), False),
(Decimal('0.0009'), False),
(Decimal('0.002'), False),
]:
with self.subTest(value=value):
self.assertEqual(cu.is_zero(value), result)
with self.subTest(value=-value):
self.assertEqual(cu.is_zero(-value), result)
@with_transaction()
def test_compute_simple(self):
'Simple conversion'