Support integer as price to round
issue10720 review375381002 (grafted from 9780dfb370fae591f5a85342e26b4278773267cf) --HG-- branch : 6.0
This commit is contained in:
1 parent
9860840640
commit
00bc7c52e2
2 files changed
+13
No files matched your search
@@ -44,6 +44,8 @@ price_digits = (16, price_decimal)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ from trytond.pool import Pool
|
||||
|
||||
from trytond.modules.company.tests import CompanyTestMixin
|
||||
|
||||
from ..product import round_price
|
||||
|
||||
|
||||
class ProductTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Product module'
|
||||
@@ -446,6 +448,15 @@ class ProductTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
[('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()
|
||||
|
||||
Reference in new issue
Block a user