Commit 857565fb authored by Arnaud Fontaine's avatar Arnaud Fontaine

FloatEquivalenceTester does nothing if quantity_range_{min,max} are not...

FloatEquivalenceTester does nothing if quantity_range_{min,max} are not defined so raises an exception showing the misconfiguration.
parent 0beae288
...@@ -31,6 +31,7 @@ from DateTime import DateTime ...@@ -31,6 +31,7 @@ from DateTime import DateTime
from Products.ERP5Type.Core.Predicate import Predicate from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.mixin.equivalence_tester import EquivalenceTesterMixin from Products.ERP5.mixin.equivalence_tester import EquivalenceTesterMixin
from Products.ERP5Type.Errors import SimulationError
class DateTimeEquivalenceTester(Predicate, EquivalenceTesterMixin): class DateTimeEquivalenceTester(Predicate, EquivalenceTesterMixin):
""" """
...@@ -92,3 +93,9 @@ class DateTimeEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -92,3 +93,9 @@ class DateTimeEquivalenceTester(Predicate, EquivalenceTesterMixin):
'The difference of ${property_name} between decision and prevision is larger than ${value}.', 'The difference of ${property_name} between decision and prevision is larger than ${value}.',
dict(property_name=tested_property, dict(property_name=tested_property,
value=absolute_tolerance_max)) value=absolute_tolerance_max))
if (absolute_tolerance_max is None and
absolute_tolerance_min is None):
raise SimulationError(
"%r: Either Absolute Tolerance, Absolute Tolerance (Min) or Absolute Tolerance"
"(Max) *must* be defined on a DateTime Divergence Tester" % self)
...@@ -34,6 +34,7 @@ from AccessControl import ClassSecurityInfo ...@@ -34,6 +34,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Core.Predicate import Predicate from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.mixin.equivalence_tester import EquivalenceTesterMixin from Products.ERP5.mixin.equivalence_tester import EquivalenceTesterMixin
from Products.ERP5Type.Errors import SimulationError
ROUNDING_OPTION_DICT = {name: value ROUNDING_OPTION_DICT = {name: value
for name, value in decimal.__dict__.items() for name, value in decimal.__dict__.items()
...@@ -117,6 +118,13 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -117,6 +118,13 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
value=absolute_tolerance_max)) value=absolute_tolerance_max))
tolerance_base = self.getProperty('tolerance_base') tolerance_base = self.getProperty('tolerance_base')
if (absolute_tolerance_min is None and
absolute_tolerance_max is None and
tolerance_base is None):
raise SimulationError(
"%r: Either Absolute Tolerance (Min) or Absolute Tolerance (Max) or "
"Relative Tolerance Base *must* be defined." % self)
base = None base = None
if tolerance_base == 'resource_quantity_precision': if tolerance_base == 'resource_quantity_precision':
# Precision of this movement's resource base unit quantity # Precision of this movement's resource base unit quantity
...@@ -171,6 +179,12 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -171,6 +179,12 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
dict(property_name=tested_property, dict(property_name=tested_property,
value=relative_tolerance_max)) value=relative_tolerance_max))
if (relative_tolerance_min is None and
relative_tolerance_max is None):
raise SimulationError(
"%r: Either Relative Tolerance (Min) or Relative Tolerance"
"(Max) *must* be defined." % self)
def _round(self, value): def _round(self, value):
rounding_option = ROUNDING_OPTION_DICT[self.getDecimalRoundingOption()] rounding_option = ROUNDING_OPTION_DICT[self.getDecimalRoundingOption()]
exponent = decimal.Decimal(self.getDecimalExponent()) exponent = decimal.Decimal(self.getDecimalExponent())
......
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