From 35aa1cab8d57b47de2a313d028071a50cf91a568 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 5 Aug 2010 12:48:38 +0000
Subject: [PATCH] delete solver decision that are no longer applicable

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37542 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/SolverProcess.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Document/SolverProcess.py b/product/ERP5/Document/SolverProcess.py
index bff342bda4..9570c06232 100644
--- a/product/ERP5/Document/SolverProcess.py
+++ b/product/ERP5/Document/SolverProcess.py
@@ -249,6 +249,7 @@ class SolverProcess(XMLObject, ActiveProcess):
     # Now build the solver decision instances based on the previous
     # grouping
     solver_decision_list = self.objectValues(portal_type='Solver Decision')
+    unmatched_solver_decision_list = set(solver_decision_list)
     for solver_decision_key, movement_dict in solver_decision_dict.items():
       causality, delivery_list, solver_list = solver_decision_key
       movement_url_list = [x.getRelativeUrl() for x in movement_dict.keys()]
@@ -257,6 +258,7 @@ class SolverProcess(XMLObject, ActiveProcess):
         x for x in solver_decision_list \
         if sorted(x.getDeliveryList()) == movement_url_list and \
         x.getCausality() == causality]
+      unmatched_solver_decision_list.difference_update(matched_solver_decision_list)
       if len(matched_solver_decision_list) > 0:
         solver_decision_list.remove(matched_solver_decision_list[0])
       else:
@@ -282,8 +284,13 @@ class SolverProcess(XMLObject, ActiveProcess):
         #   if self not in solver_list:
         #     simulation_movement.setSolverValueList(
         #       solver_list + [self])
-    # XXX what should we do for non-matched existing solver decisions?
-    # do we need to cancel them by using an appropriate workflow?
+
+
+    # delete non-matched existing solver decisions, unless they have been
+    # solved already (we detect this by the fact that the solver decision is
+    # associated to a target solver)
+    self.manage_delObjects(ids=[x.getId() for x in
+          unmatched_solver_decision_list if not x.getCausality()])
 
   def _generateRandomId(self):
     # call ActiveProcess._generateRandomId() explicitly otherwise
-- 
2.30.9