From d64a31f4a001da46cee6028d90bbc81dbd14805c Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Tue, 12 Oct 2010 10:54:55 +0000
Subject: [PATCH] 2010-10-12 yo * Fix an error that calculate may be called too
 early before a new simulation movement is indexed.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39050 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...lationMovement_calculateCausalityState.xml | 126 ++++++++++++++++++
 ...lationMovement_calculateCausalityState.xml |  17 +--
 bt5/erp5_base/bt/change_log                   |   3 +
 bt5/erp5_base/bt/revision                     |   2 +-
 4 files changed, 139 insertions(+), 9 deletions(-)
 create mode 100644 bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/SimulationMovement_calculateCausalityState.xml

diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/SimulationMovement_calculateCausalityState.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/SimulationMovement_calculateCausalityState.xml
new file mode 100644
index 0000000000..8e19533ca9
--- /dev/null
+++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/SimulationMovement_calculateCausalityState.xml
@@ -0,0 +1,126 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string>delivery_movement = context.getDeliveryValue()\n
+\n
+if delivery_movement is not None:\n
+  delivery = delivery_movement.getRootDeliveryValue()\n
+  delivery.activate().Delivery_calculate()\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>0</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>delivery_movement</string>
+                            <string>None</string>
+                            <string>delivery</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>SimulationMovement_calculateCausalityState</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_base/WorkflowTemplateItem/portal_workflow/simulation_movement_causality_interaction_workflow/scripts/SimulationMovement_calculateCausalityState.xml b/bt5/erp5_base/WorkflowTemplateItem/portal_workflow/simulation_movement_causality_interaction_workflow/scripts/SimulationMovement_calculateCausalityState.xml
index c91bc1be38..d33ce19da4 100644
--- a/bt5/erp5_base/WorkflowTemplateItem/portal_workflow/simulation_movement_causality_interaction_workflow/scripts/SimulationMovement_calculateCausalityState.xml
+++ b/bt5/erp5_base/WorkflowTemplateItem/portal_workflow/simulation_movement_causality_interaction_workflow/scripts/SimulationMovement_calculateCausalityState.xml
@@ -52,11 +52,13 @@
             <key> <string>_body</string> </key>
             <value> <string>simulation_movement = state_change[\'object\']\n
 \n
-delivery_movement = simulation_movement.getDeliveryValue()\n
-\n
-if delivery_movement is not None:\n
-  delivery = delivery_movement.getExplanationValue()\n
-  delivery.activate().Delivery_calculate()\n
+# It is not quite useful to invoke the method calculate when a newly created\n
+# simulation movement is not indexed yet, so it is better to wait for the indexing\n
+# to be done.\n
+path = simulation_movement.getPath()\n
+method_id_list = (\'immediateReindexObject\', \'recursiveImmediateReindexObject\')\n
+simulation_movement.activate(after_path_and_method_id=(path, method_id_list)) \\\n
+    .SimulationMovement_calculateCausalityState()\n
 </string> </value>
         </item>
         <item>
@@ -115,9 +117,8 @@ if delivery_movement is not None:\n
                             <string>_getitem_</string>
                             <string>simulation_movement</string>
                             <string>_getattr_</string>
-                            <string>delivery_movement</string>
-                            <string>None</string>
-                            <string>delivery</string>
+                            <string>path</string>
+                            <string>method_id_list</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_base/bt/change_log b/bt5/erp5_base/bt/change_log
index fac8213101..bd1ed94609 100644
--- a/bt5/erp5_base/bt/change_log
+++ b/bt5/erp5_base/bt/change_log
@@ -1,3 +1,6 @@
+2010-10-12 yo
+* Fix an error that calculate may be called too early before a new simulation movement is indexed.
+
 2010-10-12 yo
 * Tweak the configurations of several interaction workflows for optimization.
 
diff --git a/bt5/erp5_base/bt/revision b/bt5/erp5_base/bt/revision
index ad7876489d..ce125d2e28 100644
--- a/bt5/erp5_base/bt/revision
+++ b/bt5/erp5_base/bt/revision
@@ -1 +1 @@
-871
\ No newline at end of file
+879
\ No newline at end of file
-- 
2.30.9