From b189aa17c92f5c22bea0cddde66346a6f3ea6074 Mon Sep 17 00:00:00 2001 From: Yusei Tahara <yusei@nexedi.com> Date: Fri, 2 Apr 2010 03:44:39 +0000 Subject: [PATCH] Fix a bug which occurs on special properties like total_price. getProperty('total_price') was not rounded. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34259 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/RoundingModel.py | 10 ++++++++++ product/ERP5/tests/testRoundingTool.py | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/product/ERP5/Document/RoundingModel.py b/product/ERP5/Document/RoundingModel.py index 7dbbd55f13..8d2d9d7dad 100644 --- a/product/ERP5/Document/RoundingModel.py +++ b/product/ERP5/Document/RoundingModel.py @@ -90,6 +90,7 @@ class RoundingModel(Predicate): """ rounding_model = self rounded_property_getter_method_name_list = [] + rounded_property_special_property_name_list = [] if isinstance(document, RoundingProxy): temp_document = document._getOriginalDocument() @@ -120,6 +121,8 @@ class RoundingModel(Predicate): # cannot round the property value so that the return value of getter # will be rounded rounded_property_getter_method_name_list.append(getter_name) + if getter is not None and setter is None: + rounded_property_special_property_name_list.append(property_id) class _RoundingProxy(RoundingProxy): @@ -141,6 +144,13 @@ class RoundingModel(Predicate): else: return None + def getProperty(self, key, *args, **kw): + result = original_document.getProperty(key, *args, **kw) + if key in rounded_property_special_property_name_list: + return rounding_model.roundValue(result) + else: + return result + def __getattr__(self, name): attribute = getattr(original_document, name) if getattr(attribute, 'DUMMY_ROUNDING_METHOD_MARK', None) is DUMMY_ROUNDING_METHOD_MARK: diff --git a/product/ERP5/tests/testRoundingTool.py b/product/ERP5/tests/testRoundingTool.py index a62192f035..969c646e03 100644 --- a/product/ERP5/tests/testRoundingTool.py +++ b/product/ERP5/tests/testRoundingTool.py @@ -71,8 +71,11 @@ class TestRoundingTool(ERP5TypeTestCase): # check values of empty line self.assertEqual(sale_order_line.getPrice(), None) + self.assertEqual(sale_order_line.getProperty('price'), None) self.assertEqual(sale_order_line.getQuantity(), 0.0) + self.assertEqual(sale_order_line.getProperty('quantity'), 0.0) self.assertEqual(sale_order_line.getTotalPrice(), 0.0) + self.assertEqual(sale_order_line.getProperty('total_price'), 0.0) self.login('developer') # rounding model dummy never match to sale order line @@ -105,8 +108,11 @@ class TestRoundingTool(ERP5TypeTestCase): # rounding model does not do anything to empty values like None wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) self.assertEqual(wrapped_line.getPrice(), None) + self.assertEqual(wrapped_line.getProperty('price'), None) self.assertEqual(wrapped_line.getQuantity(), 0.0) + self.assertEqual(wrapped_line.getProperty('quantity'), 0.0) self.assertEqual(wrapped_line.getTotalPrice(), 0.0) + self.assertEqual(wrapped_line.getProperty('total_price'), 0.0) self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) @@ -121,14 +127,20 @@ class TestRoundingTool(ERP5TypeTestCase): self.tic() self.assertEqual(sale_order_line.getPrice(), 123.456) + self.assertEqual(sale_order_line.getProperty('price'), 123.456) self.assertEqual(sale_order_line.getQuantity(), 78.91) + self.assertEqual(sale_order_line.getProperty('quantity'), 78.91) self.assertEqual(sale_order_line.getTotalPrice(), 123.456*78.91) + self.assertEqual(sale_order_line.getProperty('total_price'), 123.456*78.91) # check if price is rounded wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) self.assertEqual(wrapped_line.getPrice(), 123.45) + self.assertEqual(wrapped_line.getProperty('price'), 123.45) self.assertEqual(wrapped_line.getQuantity(), 78.91) + self.assertEqual(wrapped_line.getProperty('quantity'), 78.91) self.assertEqual(wrapped_line.getTotalPrice(), 123.45*78.91) + self.assertEqual(wrapped_line.getProperty('total_price'), 123.45*78.91) self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) @@ -149,8 +161,11 @@ class TestRoundingTool(ERP5TypeTestCase): # if rounding model is not validated, then it is not applied wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) self.assertEqual(wrapped_line.getPrice(), 123.45) + self.assertEqual(wrapped_line.getProperty('price'), 123.45) self.assertEqual(wrapped_line.getQuantity(), 78.91) + self.assertEqual(wrapped_line.getProperty('quantity'), 78.91) self.assertEqual(wrapped_line.getTotalPrice(), 123.45*78.91) + self.assertEqual(wrapped_line.getProperty('total_price'), 123.45*78.91) self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) @@ -165,8 +180,11 @@ class TestRoundingTool(ERP5TypeTestCase): # now, rounding model is validated, so it is applied wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) self.assertEqual(wrapped_line.getPrice(), 123.45) + self.assertEqual(wrapped_line.getProperty('price'), 123.45) self.assertEqual(wrapped_line.getQuantity(), 79.0) + self.assertEqual(wrapped_line.getProperty('quantity'), 79.0) self.assertEqual(wrapped_line.getTotalPrice(), 123.45*79.0) + self.assertEqual(wrapped_line.getProperty('total_price'), 123.45*79.0) self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), 1) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) @@ -187,8 +205,11 @@ class TestRoundingTool(ERP5TypeTestCase): # check if price and quantity and total price are rounded wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) self.assertEqual(wrapped_line.getPrice(), 123.45) + self.assertEqual(wrapped_line.getProperty('price'), 123.45) self.assertEqual(wrapped_line.getQuantity(), 79.0) + self.assertEqual(wrapped_line.getProperty('quantity'), 79.0) self.assertEqual(wrapped_line.getTotalPrice(), 9750.0) + self.assertEqual(wrapped_line.getProperty('total_price'), 9750.0) self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), 1) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), -1) -- 2.30.9