Commit 2fcbb5bf authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support roundings.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34055 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4e1f9a31
...@@ -56,6 +56,7 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -56,6 +56,7 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
, PropertySheet.DublinCore , PropertySheet.DublinCore
, PropertySheet.EquivalenceTester , PropertySheet.EquivalenceTester
, PropertySheet.SolverSelection , PropertySheet.SolverSelection
, PropertySheet.DecimalOption
) )
# Declarative interfaces # Declarative interfaces
...@@ -79,6 +80,10 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -79,6 +80,10 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
prevision_movement.getDelivery() == decision_movement.getRelativeUrl(): prevision_movement.getDelivery() == decision_movement.getRelativeUrl():
decision_value *= prevision_movement.getDeliveryRatio() decision_value *= prevision_movement.getDeliveryRatio()
if self.isDecimalAlignmentEnabled():
decision_value = self._round(decision_value)
prevision_value = self._round(prevision_value)
delta = decision_value - prevision_value delta = decision_value - prevision_value
# XXX we should use appropriate property sheets and getter methods # XXX we should use appropriate property sheets and getter methods
# for these properties. # for these properties.
...@@ -145,10 +150,23 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -145,10 +150,23 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
dict(property_name=tested_property, dict(property_name=tested_property,
value=relative_tolerance_max)) value=relative_tolerance_max))
return None return None
# XXX the followings are not treated yet:
# * decimal_alignment_enabled def _round(self, value):
# * decimal_rounding_option from decimal import (Decimal, ROUND_DOWN, ROUND_UP, ROUND_CEILING,
# * decimal_exponent ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN,
ROUND_HALF_UP)
# Python2.4 did not support ROUND_05UP yet.
rounding_option_dict = {'ROUND_DOWN':ROUND_DOWN,
'ROUND_UP':ROUND_UP,
'ROUND_CEILING':ROUND_CEILING,
'ROUND_FLOOR':ROUND_FLOOR,
'ROUND_HALF_DOWN':ROUND_HALF_DOWN,
'ROUND_HALF_EVEN':ROUND_HALF_EVEN,
'ROUND_HALF_UP':ROUND_HALF_UP}
rounding_option = rounding_option_dict.get(self.getDecimalRoundingOption(),
ROUND_DOWN)
return Decimal(str(value)).quantize(Decimal(self.getDecimalExponent()),
rounding=rounding_option)
def getUpdatablePropertyDict(self, prevision_movement, decision_movement): def getUpdatablePropertyDict(self, prevision_movement, decision_movement):
""" """
......
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