From c0e30e109608791e2f655de458f6e528686c7ec6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 15 Dec 2005 15:30:45 +0000
Subject: [PATCH] Reexpand when necessary for invoice transaction rule, where
 the "do not expand if it has already been expanded" behaviour doesn't always
 work (when you change a category on the line that would change Invoice
 Transaction Rule's matching cell)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4669 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/SimulationMovement.py | 44 +++++++--------------
 1 file changed, 14 insertions(+), 30 deletions(-)

diff --git a/product/ERP5/Document/SimulationMovement.py b/product/ERP5/Document/SimulationMovement.py
index d3b6a9b888..c0f82b4087 100755
--- a/product/ERP5/Document/SimulationMovement.py
+++ b/product/ERP5/Document/SimulationMovement.py
@@ -200,8 +200,6 @@ class SimulationMovement(Movement):
   security.declareProtected(Permissions.ModifyPortalContent, 'expand')
   def expand(self, **kw):
     """
-      -> new status : expanded
-
       Parses all existing applied rules and make sure they apply.
       Checks other possible rules and starts expansion process
       (instanciates rule and calls expand on rule)
@@ -209,45 +207,31 @@ class SimulationMovement(Movement):
       Only movements which applied rule parent is expanded can
       be expanded.
     """
-    #LOG('In simulation expand',0, str(self.id))
-#     self.reindexObject()
-    if self.getCausalityState() == 'expanded':
+    # XXX Default behaviour is not to expand if it has already been
+    # expanded, but some rules are configuration rules and need to be
+    # reexpanded  each time, because the rule apply only if predicates
+    # are true, then this kind of rule must always be tested. Currently,
+    # we know that invoicing rule acts like this, and that it comes after
+    # invoice or invoicing_rule, so we if we come from invoince rule or 
+    # invoicing rule, we always expand regardless of the causality state.
+    if (self.getParent().getSpecialiseId() not in 
+         ('default_invoicing_rule', 'default_invoice_rule')
+         and self.getCausalityState() == 'expanded' ) or \
+         len(self.objectIds()) != 0:
       # Reexpand
       for my_applied_rule in self.objectValues():
         my_applied_rule.expand(**kw)
     else:
       portal_rules = getToolByName(self, 'portal_rules')
-      # Parse each applied rule and test if it applied
-      #for applied_rule in self.objectValues():
-      #  if not applied_rule.test():
-      #    # delete
       # Parse each rule and test if it applies
       for rule in portal_rules.objectValues():
         if rule.test(self):
-          my_applied_rule = rule.constructNewAppliedRule(self,**kw)
-          my_applied_rule.expand(**kw)
+          my_applied_rule = rule.constructNewAppliedRule(self, **kw)
+      for my_applied_rule in self.objectValues() :
+        my_applied_rule.expand(**kw)
       # Set to expanded
       self.setCausalityState('expanded')
 
-  #expand = WorkflowMethod(expand) USELESS NOW
-
-# XXX moved to Portal Simulation
-#   security.declareProtected(Permissions.ModifyPortalContent, 'solve')
-#   def solve(self, solver, new_target=None):
-#     """
-#        Makes the movement expandable again
-# 
-#        -> new status -> solved
-# 
-#        Once a movement has been updated with consistent
-#        target and planned values, it is marked as solved
-#        and can therefore be expanded again
-#     """
-#     self.portal_simulation.applyTargetSolver(self, solver, new_target=new_target)
-#     self.setCausalityState('solved')
-# 
-#   #solve = WorkflowMethod(solve) USELESS NOW
-
   security.declareProtected(Permissions.ModifyPortalContent, 'diverge')
   def diverge(self):
     """
-- 
2.30.9