Commit b189aa17 authored by Yusei Tahara's avatar Yusei Tahara

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
parent 29e56530
...@@ -90,6 +90,7 @@ class RoundingModel(Predicate): ...@@ -90,6 +90,7 @@ class RoundingModel(Predicate):
""" """
rounding_model = self rounding_model = self
rounded_property_getter_method_name_list = [] rounded_property_getter_method_name_list = []
rounded_property_special_property_name_list = []
if isinstance(document, RoundingProxy): if isinstance(document, RoundingProxy):
temp_document = document._getOriginalDocument() temp_document = document._getOriginalDocument()
...@@ -120,6 +121,8 @@ class RoundingModel(Predicate): ...@@ -120,6 +121,8 @@ class RoundingModel(Predicate):
# cannot round the property value so that the return value of getter # cannot round the property value so that the return value of getter
# will be rounded # will be rounded
rounded_property_getter_method_name_list.append(getter_name) 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): class _RoundingProxy(RoundingProxy):
...@@ -141,6 +144,13 @@ class RoundingModel(Predicate): ...@@ -141,6 +144,13 @@ class RoundingModel(Predicate):
else: else:
return None 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): def __getattr__(self, name):
attribute = getattr(original_document, name) attribute = getattr(original_document, name)
if getattr(attribute, 'DUMMY_ROUNDING_METHOD_MARK', None) is DUMMY_ROUNDING_METHOD_MARK: if getattr(attribute, 'DUMMY_ROUNDING_METHOD_MARK', None) is DUMMY_ROUNDING_METHOD_MARK:
......
...@@ -71,8 +71,11 @@ class TestRoundingTool(ERP5TypeTestCase): ...@@ -71,8 +71,11 @@ class TestRoundingTool(ERP5TypeTestCase):
# check values of empty line # check values of empty line
self.assertEqual(sale_order_line.getPrice(), None) 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.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.getTotalPrice(), 0.0)
self.assertEqual(sale_order_line.getProperty('total_price'), 0.0)
self.login('developer') self.login('developer')
# rounding model dummy never match to sale order line # rounding model dummy never match to sale order line
...@@ -105,8 +108,11 @@ class TestRoundingTool(ERP5TypeTestCase): ...@@ -105,8 +108,11 @@ class TestRoundingTool(ERP5TypeTestCase):
# rounding model does not do anything to empty values like None # rounding model does not do anything to empty values like None
wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line)
self.assertEqual(wrapped_line.getPrice(), None) self.assertEqual(wrapped_line.getPrice(), None)
self.assertEqual(wrapped_line.getProperty('price'), None)
self.assertEqual(wrapped_line.getQuantity(), 0.0) 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.getTotalPrice(), 0.0)
self.assertEqual(wrapped_line.getProperty('total_price'), 0.0)
self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2) self.assertEqual(wrapped_line.getRoundingModelPrecision('price'), 2)
self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None)
self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None)
...@@ -121,14 +127,20 @@ class TestRoundingTool(ERP5TypeTestCase): ...@@ -121,14 +127,20 @@ class TestRoundingTool(ERP5TypeTestCase):
self.tic() self.tic()
self.assertEqual(sale_order_line.getPrice(), 123.456) 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.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.getTotalPrice(), 123.456*78.91)
self.assertEqual(sale_order_line.getProperty('total_price'), 123.456*78.91)
# check if price is rounded # check if price is rounded
wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line)
self.assertEqual(wrapped_line.getPrice(), 123.45) 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.getQuantity(), 78.91)
self.assertEqual(wrapped_line.getProperty('quantity'), 78.91)
self.assertEqual(wrapped_line.getTotalPrice(), 123.45*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('price'), 2)
self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None)
self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None)
...@@ -149,8 +161,11 @@ class TestRoundingTool(ERP5TypeTestCase): ...@@ -149,8 +161,11 @@ class TestRoundingTool(ERP5TypeTestCase):
# if rounding model is not validated, then it is not applied # if rounding model is not validated, then it is not applied
wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line)
self.assertEqual(wrapped_line.getPrice(), 123.45) 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.getQuantity(), 78.91)
self.assertEqual(wrapped_line.getProperty('quantity'), 78.91)
self.assertEqual(wrapped_line.getTotalPrice(), 123.45*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('price'), 2)
self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), None)
self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None)
...@@ -165,8 +180,11 @@ class TestRoundingTool(ERP5TypeTestCase): ...@@ -165,8 +180,11 @@ class TestRoundingTool(ERP5TypeTestCase):
# now, rounding model is validated, so it is applied # now, rounding model is validated, so it is applied
wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line)
self.assertEqual(wrapped_line.getPrice(), 123.45) 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.getQuantity(), 79.0)
self.assertEqual(wrapped_line.getProperty('quantity'), 79.0)
self.assertEqual(wrapped_line.getTotalPrice(), 123.45*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('price'), 2)
self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), 1) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), 1)
self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), None)
...@@ -187,8 +205,11 @@ class TestRoundingTool(ERP5TypeTestCase): ...@@ -187,8 +205,11 @@ class TestRoundingTool(ERP5TypeTestCase):
# check if price and quantity and total price are rounded # check if price and quantity and total price are rounded
wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line) wrapped_line = rounding_tool.getRoundingProxy(sale_order_line, sale_order_line)
self.assertEqual(wrapped_line.getPrice(), 123.45) 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.getQuantity(), 79.0)
self.assertEqual(wrapped_line.getProperty('quantity'), 79.0)
self.assertEqual(wrapped_line.getTotalPrice(), 9750.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('price'), 2)
self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), 1) self.assertEqual(wrapped_line.getRoundingModelPrecision('quantity'), 1)
self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), -1) self.assertEqual(wrapped_line.getRoundingModelPrecision('total_price'), -1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment