From 62fe5b3fdfacaad54ab1affb603aa3fd9e5630fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 14 Oct 2024 14:35:37 +0200 Subject: [PATCH] Enforce strictly positive rounding value for currency Closes #13600 --- modules/currency/currency.py | 3 ++ modules/currency/tests/test_module.py | 60 --------------------------- 2 files changed, 3 insertions(+), 60 deletions(-) diff --git a/modules/currency/currency.py b/modules/currency/currency.py index 747cf5d502..7418c31293 100644 --- a/modules/currency/currency.py +++ b/modules/currency/currency.py @@ -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.") diff --git a/modules/currency/tests/test_module.py b/modules/currency/tests/test_module.py index 206877b8a9..02e28007d7 100644 --- a/modules/currency/tests/test_module.py +++ b/modules/currency/tests/test_module.py @@ -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'