changeset 9780dfb370fa in modules/product:default
details: https://hg.tryton.org/modules/product?cmd=changeset&node=9780dfb370fa
description:
Support integer as price to round
issue10720
review375381002
diffstat:
product.py | 2 ++
tests/test_product.py | 11 +++++++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diffs (40 lines):
diff -r 20c2b318b42f -r 9780dfb370fa product.py
--- a/product.py Mon Aug 30 23:58:28 2021 +0200
+++ b/product.py Mon Sep 13 23:07:13 2021 +0200
@@ -44,6 +44,8 @@
def round_price(value, rounding=None):
"Round price using the price digits"
+ if isinstance(value, int):
+ return Decimal(value)
return value.quantize(
Decimal(1) / 10 ** price_digits[1], rounding=rounding)
diff -r 20c2b318b42f -r 9780dfb370fa tests/test_product.py
--- a/tests/test_product.py Mon Aug 30 23:58:28 2021 +0200
+++ b/tests/test_product.py Mon Sep 13 23:07:13 2021 +0200
@@ -12,6 +12,8 @@
from trytond.modules.company.tests import CompanyTestMixin
+from ..product import round_price
+
class ProductTestCase(CompanyTestMixin, ModuleTestCase):
'Test Product module'
@@ -446,6 +448,15 @@
[('name', 'like', '%')], order=[('type', 'DESC')]),
[product2, product1])
+ def test_round_price(self):
+ for value, result in [
+ (Decimal('1'), Decimal('1.0000')),
+ (Decimal('1.12345'), Decimal('1.1234')),
+ (1, Decimal('1')),
+ ]:
+ with self.subTest(value=value):
+ self.assertEqual(round_price(value), result)
+
def suite():
suite = trytond.tests.test_tryton.suite()