From 3402068c5a09d90290de082011a82676260f0db8 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 15 Nov 2009 23:15:00 +0000
Subject: [PATCH] Moved code from SolverTool to SolverProcess.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30638 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/SolverProcess.py | 47 ++++++++++++++++++++++++++
 product/ERP5/Tool/SolverTool.py        | 27 +++------------
 2 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/product/ERP5/Document/SolverProcess.py b/product/ERP5/Document/SolverProcess.py
index e5cf2009c5..f239d950db 100644
--- a/product/ERP5/Document/SolverProcess.py
+++ b/product/ERP5/Document/SolverProcess.py
@@ -137,3 +137,50 @@ class SolverProcess(XMLObject, ActiveProcess):
     """
     for solver in self.contentValues(portal_type=self.getPortalObject().getPortalTargetSolverTypeList()):
       solver.activate(active_process=self).solve()
+
+
+  # API
+  def isSolverDecisionListConsistent(self):
+    """
+    Returns True is the Solver Process decisions do not 
+    need to be rebuilt, False else. This method can be
+    invoked before invoking buildSolverDecisionList if
+    this helps reducing CPU time.
+    """
+
+  def buildSolverDecisionList(self, delivery_or_movement=None):
+    """
+    Build (or rebuild) the solver decisions in the solver process
+
+    delivery_or_movement -- a movement, a delivery, 
+                            or a list thereof
+    """
+    if delivery_or_movement is None:
+      raise NotImplementedError
+      # Gather all delivery lines already found
+      # in already built solvers
+
+    # We suppose here that delivery_or_movement is a list of
+    # delivery lines. Let group decisions in such way
+    # that a single decision is created per divergence tester instance
+    # and per application level list
+    solver_decision_dict = {}
+    for movement in delivery_or_movement:
+      for simulation_movement in movement.getDeliveryRelatedValueList():
+        simulation_movemet_url = simulation_movement.getRelativeUrl()
+        for divergence_tester in simulation_movement.getParentValue().getDivergenceTesterValueList():
+          application_list = map(lambda x:x.getRelativeUrl(), 
+                 self.getSolverDecisionApplicationValueList(simulation_movement, divergence_tester))
+          application_list.sort()
+          solver_decision_key = (divergence_tester.getRelativeUrl(), application_list)
+          movement_dict = solver_decision_dict.setdefaults(solver_decision_key, {})
+          movement_dict[simulation_movemet_url] = None
+
+    # Now build the solver decision instances based on the previous
+    # grouping
+    #  XXX-JPS: pseudocode for update (ie. rebuild) is not present
+    for solver_decision_key, movement_dict in solver_decision_dict.items():
+      new_decision = self.newContent(portal_type='Solver Decision')
+      new_decision._setDeliveryList(movement_dict.keys())
+      new_decision._setSolver(solver_decision_key[0])
+      # No need to set application_list or....?
diff --git a/product/ERP5/Tool/SolverTool.py b/product/ERP5/Tool/SolverTool.py
index c848fcc528..831e22e9cb 100644
--- a/product/ERP5/Tool/SolverTool.py
+++ b/product/ERP5/Tool/SolverTool.py
@@ -143,30 +143,11 @@ class SolverTool(BaseTool):
     if not self.isDivergent(delivery_or_movement=delivery_or_movement):
       return None
 
-    # We suppose here that delivery_or_movement is a list of
-    # delivery lines. Let group decisions in such way
-    # that a single decision is created per divergence tester instance
-    # and per application level list
-    solver_decision_dict = {}
-    for movement in delivery_or_movement:
-      for simulation_movement in movement.getDeliveryRelatedValueList():
-        simulation_movemet_url = simulation_movement.getRelativeUrl()
-        for divergence_tester in simulation_movement.getParentValue().getDivergenceTesterValueList():
-          application_list = map(lambda x:x.getRelativeUrl(), 
-                 self.getSolverDecisionApplicationValueList(simulation_movement, divergence_tester))
-          application_list.sort()
-          solver_decision_key = (divergence_tester.getRelativeUrl(), application_list)
-          movement_dict = solver_decision_dict.setdefaults(solver_decision_key, {})
-          movement_dict[simulation_movemet_url] = None
-
-    # Now build the solver process instances based on the previous
-    # grouping
+    # Create an empty solver process
     new_solver = self.newContent(portal_type='Solver Process')
-    for solver_decision_key, movement_dict in solver_decision_dict.items():
-      new_decision = self.newContent(portal_type='Solver Decision')
-      new_decision._setDeliveryList(movement_dict.keys())
-      new_decision._setSolver(solver_decision_key[0])
-      # No need to set application_list or....?
+    # And build decisions
+    new_solver.updateSolverDecision(delivery_or_movement=delivery_or_movement)
+    return new_solver
 
   def getSolverProcessValueList(self, delivery_or_movement=None, validation_state=None):
     """
-- 
2.30.9