diff --git a/wger/manager/dataclasses.py b/wger/manager/dataclasses.py index f75100bc5..e1a0b48d6 100644 --- a/wger/manager/dataclasses.py +++ b/wger/manager/dataclasses.py @@ -228,7 +228,8 @@ def round_value( If the base is None, the value will be returned as a Decimal object. """ - if x is None: + + if x is None or base == 0: return x # If the result is an integer, remove the decimal part diff --git a/wger/manager/tests/test_dataclasses_helper.py b/wger/manager/tests/test_dataclasses_helper.py index 0006f3d11..09d902403 100644 --- a/wger/manager/tests/test_dataclasses_helper.py +++ b/wger/manager/tests/test_dataclasses_helper.py @@ -33,8 +33,11 @@ def test_round_value(self): def test_round_value2(self): self.assertEqual(round_value(Decimal('7'), 1.25), Decimal('7.5')) - def test_round_value_no_base(self): + def test_round_value_base_none(self): self.assertEqual(round_value(Decimal('1.33')), Decimal('1.33')) + def test_round_value_base_zero(self): + self.assertEqual(round_value(Decimal('1.33'), 0), Decimal('1.33')) + def test_round_no_value(self): self.assertEqual(round_value(None), None)