diff --git a/product/ERP5/mixin/rule.py b/product/ERP5/mixin/rule.py index 06590875e38456481c600bbf22e1d7565c26f340..33987e0c514bb8bf7088b894c8a4487ab5c15a61 100644 --- a/product/ERP5/mixin/rule.py +++ b/product/ERP5/mixin/rule.py @@ -157,6 +157,25 @@ class RuleMixin: self._getMovementGeneratorContext(context), movement_list=self._getMovementGeneratorMovementList(), rounding=rounding) + # Prepare a mapping between prevision and decision + # The prevision_to_decision_map is a list of tuples + # of the form (prevision_movement_dict, list of decision_movement) + prevision_to_decision_map = [] + + # XXX First we try to match by 'order' value if possible. + matched_prevision_list = [] + matched_decision_list = [] + prevision_order_dict = dict( + (x.getOrder(), x) for x in prevision_movement_list) + for decision_movement in decision_movement_list: + prevision_movement = prevision_order_dict.get( + decision_movement.getOrder(), None) + if prevision_movement is not None: + prevision_to_decision_map.append( + (prevision_movement, [decision_movement])) + matched_prevision_list.append(prevision_movement) + matched_decision_list.append(decision_movement) + # Get divergence testers tester_list = self._getMatchingTesterList() if len(tester_list) == 0: @@ -165,6 +184,8 @@ class RuleMixin: # Create small groups of movements per hash keys decision_movement_dict = {} for movement in decision_movement_list: + if movement in matched_decision_list: + continue tester_key = [] for tester in tester_list: if tester.test(movement): @@ -175,6 +196,8 @@ class RuleMixin: decision_movement_dict.setdefault(tester_key, []).append(movement) prevision_movement_dict = {} for movement in prevision_movement_list: + if movement in matched_prevision_list: + continue tester_key = [] for tester in tester_list: if tester.test(movement): @@ -184,11 +207,6 @@ class RuleMixin: tester_key = tuple(tester_key) prevision_movement_dict.setdefault(tester_key, []).append(movement) - # Prepare a mapping between prevision and decision - # The prevision_to_decision_map is a list of tuples - # of the form (prevision_movement_dict, list of decision_movement) - prevision_to_decision_map = [] - # First find out all existing (decision) movements which belong to no group no_group_list = [] for tester_key in decision_movement_dict.keys(): @@ -217,6 +235,7 @@ class RuleMixin: map_list = [] for decision_movement in decision_movement_dict.get(tester_key, ()): if _compare(tester_list, prevision_movement, decision_movement): + # XXX is it OK to have more than 2 decision_movements? map_list.append(decision_movement) prevision_to_decision_map.append((prevision_movement, map_list))