Commit 0a6c28bc authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add VariationDivergenceTester and remove DictDivergenceTester.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31390 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5c8bbf61
...@@ -33,7 +33,7 @@ from Products.ERP5.Document.Predicate import Predicate ...@@ -33,7 +33,7 @@ from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5.mixin.divergence_tester import DivergenceTesterMixin from Products.ERP5.mixin.divergence_tester import DivergenceTesterMixin
class DictDivergenceTester(Predicate, DivergenceTesterMixin): class VariationDivergenceTester(Predicate, DivergenceTesterMixin):
""" """
The purpose of this divergence tester is to check the The purpose of this divergence tester is to check the
consistency between delivery movement and simulation movement consistency between delivery movement and simulation movement
...@@ -59,27 +59,33 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin): ...@@ -59,27 +59,33 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin):
# Declarative interfaces # Declarative interfaces
zope.interface.implements( interfaces.IDivergenceTester, ) zope.interface.implements( interfaces.IDivergenceTester, )
def _compare(self, prevision_movement, decision_movement): def _compare(self, prevision_movement, decision_movement):
""" """
If prevision_movement and decision_movement don't match, it returns a If prevision_movement and decision_movement don't match, it returns a
list : (prevision_value, decision_value, message, mapping) list : (prevision_value, decision_value, message, mapping)
""" """
tested_property = self.getTestedProperty() for tested_property in ('variation_category_list',
if getattr(decision_movement, 'isPropertyRecorded', 'variation_property_dict'):
lambda x:False)(tested_property): if getattr(decision_movement, 'isPropertyRecorded',
decision_value = decision_movement.getRecordedProperty(tested_property) lambda x:False)(tested_property):
else: decision_value = decision_movement.getRecordedProperty(tested_property)
decision_value = decision_movement.getProperty(tested_property) else:
prevision_value = prevision_movement.getProperty(tested_property) decision_value = decision_movement.getProperty(tested_property)
prevision_value = prevision_movement.getProperty(tested_property)
# XXX do we have configurable parameter for this divergence tester ?
# like ambiguity... if isinstance(prevision_value, (list, tuple)):
if sorted(decision_value.items()) != sorted(prevision_value.items()): result = sorted(decision_value) == sorted(prevision_value)
return ( elif isinstance(prevision_value, dict):
prevision_value, decision_value, result = sorted(decision_value.items()) == \
'The value of ${property_name} is different between decision and prevision.', sorted(prevision_value.items())
dict(property_name=tested_property)) else:
# should not happen
raise AttributeError, 'prevision and decision values of this divergence tester should be list, tuple or dict.'
if not result:
return (
prevision_value, decision_value,
'The value of ${property_name} is different between decision and prevision.',
dict(property_name=tested_property))
return None return None
def getUpdatablePropertyDict(self, prevision_movement, decision_movement): def getUpdatablePropertyDict(self, prevision_movement, decision_movement):
...@@ -91,9 +97,12 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin): ...@@ -91,9 +97,12 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin):
decision_movement -- a delivery movement (decision) decision_movement -- a delivery movement (decision)
""" """
tested_property = self.getTestedProperty() property_dict = {}
prevision_value = prevision_movement.getProperty(tested_property) for tested_property in ('variation_category_list',
return {tested_property:prevision_value} 'variation_property_dict'):
prevision_value = prevision_movement.getProperty(tested_property)
property_dict[tested_property] = prevision_value
return property_dict
def accept(self, simulation_movement): def accept(self, simulation_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