From 8b7f208e9ca4bcd38c44e45c7c384d9b59c5dc91 Mon Sep 17 00:00:00 2001 From: Karla Stenger Date: Mon, 11 Jan 2016 10:28:00 -0300 Subject: [PATCH] Change Uom.round into an instance method. issue4423 review19651002 --- CHANGELOG | 1 + tests/test_product.py | 2 +- uom.py | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b6632ecb96..b3a193282c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Change Uom.round into an instance method * Add Function fields on Product from Template Version 3.8.0 - 2015-11-02 diff --git a/tests/test_product.py b/tests/test_product.py index ec5048ce2e..c0fa072d35 100644 --- a/tests/test_product.py +++ b/tests/test_product.py @@ -311,7 +311,7 @@ class ProductTestCase(ModuleTestCase): pool = Pool() Uom = pool.get('product.uom') for number, precision, result in tests: - self.assertEqual(Uom.round(number, precision), result) + self.assertEqual(Uom(rounding=precision).round(number), result) def suite(): diff --git a/uom.py b/uom.py index 4b3945d57d..cdaa26cfd0 100644 --- a/uom.py +++ b/uom.py @@ -134,8 +134,8 @@ class Uom(ModelSQL, ModelView): ('symbol',) + tuple(clause[1:]), ] - @staticmethod - def round(number, precision=1.0): + def round(self, number): + precision = self.rounding i, d = divmod(precision, 1) base = round(number / precision) # Instead of multiply by the decimal part, we must divide by the @@ -232,7 +232,7 @@ class Uom(ModelSQL, ModelView): amount = amount * to_uom.rate if round: - amount = cls.round(amount, to_uom.rounding) + amount = to_uom.round(amount) return amount