From acea640cb7fb4698b9eae30b79d2aeff055884c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 28 Apr 2009 11:16:35 +0000
Subject: [PATCH] - extend scripts to select movements to select trade model
 rule children and grand-grand children movements - put what can be put into
 single scripts and invoke them for type based ones

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26672 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../InvoiceTransaction_selectDelivery.xml     | 173 +++++++++++++++
 ...voiceTransaction_selectInvoiceMovement.xml | 195 +++++++++++++++++
 ...eTransaction_selectPackingListMovement.xml | 205 ++++++++++++++++++
 ...voiceTransaction_selectInvoiceMovement.xml | 128 +++++++++++
 ...eTransaction_selectPackingListMovement.xml |  49 +----
 ...voiceTransaction_selectInvoiceMovement.xml | 128 +++++++++++
 ...eTransaction_selectPackingListMovement.xml |  49 +----
 bt5/erp5_bpm/bt/revision                      |   2 +-
 8 files changed, 834 insertions(+), 95 deletions(-)
 create mode 100644 bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectDelivery.xml
 create mode 100644 bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectInvoiceMovement.xml
 create mode 100644 bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectPackingListMovement.xml
 create mode 100644 bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectInvoiceMovement.xml
 create mode 100644 bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectInvoiceMovement.xml

diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectDelivery.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectDelivery.xml
new file mode 100644
index 0000000000..32ad036c0c
--- /dev/null
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectDelivery.xml
@@ -0,0 +1,173 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </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>#\n
+#  This method is used by the invoice_transaction_builder\n
+# delivery builder to select the Invoice Transaction \n
+# in which creating new Invoice Transaction Lines.\n
+#\n
+\n
+deliveries_keys = {}\n
+for movement in movement_list:\n
+  ar = movement.getParentValue()\n
+  line = None\n
+\n
+  # case of tax movement  \n
+  if ar.getSpecialiseValue().getPortalType() == \'Tax Rule\':\n
+    for other_rule in ar.getParentValue().contentValues():\n
+      if other_rule == ar:\n
+        continue\n
+      for sm in other_rule.contentValues():\n
+        line = sm.getDeliveryValue()\n
+  # case of trade model movement\n
+  if ar.getParentValue().getParentValue().getSpecialiseValue().getPortalType() == \'Trade Model Rule\':\n
+    tm_related_movement = ar.getParentValue().getParentValue().getParentValue()\n
+    line = tm_related_movement.getOrderValue()\n
+    if line is None:\n
+      line = tm_related_movement.getParentValue().getParentValue().getOrderValue()\n
+\n
+  # in case of invoice rule (ie. starting from Invoice)\n
+  if line is None:\n
+    line = ar.getParentValue().getOrderValue()\n
+\n
+  # in case of invoicing rule (ie. starting from Order)\n
+  if line is None:\n
+    line = movement.getParentValue().getParentValue().getDeliveryValue()\n
+\n
+  deliveries_keys[line.getExplanationValue()] = 1\n
+\n
+return filter(lambda x : x is not None, deliveries_keys.keys())\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>movement_list, **kw</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>1</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>movement_list</string>
+                            <string>kw</string>
+                            <string>deliveries_keys</string>
+                            <string>_getiter_</string>
+                            <string>movement</string>
+                            <string>_getattr_</string>
+                            <string>ar</string>
+                            <string>None</string>
+                            <string>line</string>
+                            <string>other_rule</string>
+                            <string>sm</string>
+                            <string>tm_related_movement</string>
+                            <string>_write_</string>
+                            <string>filter</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>InvoiceTransaction_selectDelivery</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectInvoiceMovement.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectInvoiceMovement.xml
new file mode 100644
index 0000000000..d1760f6d78
--- /dev/null
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectInvoiceMovement.xml
@@ -0,0 +1,195 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </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>invoice_portal_type_mapping = {\n
+  \'Sale Invoice Transaction\': [\'Sale Order\', \'Sale Invoice Transaction\', \'Sale Packing List\'],\n
+  \'Purchase Invoice Transaction\': [\'Purchase Order\', \'Purchase Invoice Transaction\', \'Purchase Packing List\'],\n
+}\n
+src__ = kw.get(\'src__\',0)\n
+search_kw = kw.copy()\n
+\n
+search_kw[\'parent_specialise_portal_type\'] = \'Invoice Transaction Rule\'\n
+search_kw[\'explanation_portal_type\']       = invoice_portal_type_mapping[invoice_portal_type]\n
+search_kw[\'portal_type\']                   = \'Simulation Movement\'\n
+search_kw[\'grand_parent_simulation_state\'] = [\'started\']\n
+\n
+search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
+result = context.InvoiceTransaction_zSelectMovement(**search_kw)\n
+if src__:\n
+  normal_movement_list = result\n
+else:\n
+  normal_movement_list = [q for q in result]\n
+\n
+search_kw = kw.copy()\n
+\n
+search_kw[\'grand_grand_parent_specialise_portal_type\'] = \'Trade Model Rule\'\n
+search_kw[\'parent_specialise_portal_type\'] = \'Invoice Transaction Rule\'\n
+search_kw[\'explanation_portal_type\']       = invoice_portal_type_mapping[invoice_portal_type]\n
+search_kw[\'portal_type\']                   = \'Simulation Movement\'\n
+search_kw[\'grand_grand_grand_parent_simulation_state\'] = [\'started\']\n
+\n
+search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
+\n
+result = context.InvoiceTransaction_zSelectMovement(**search_kw)\n
+\n
+if src__:\n
+  trade_model_movement_list = result\n
+else:\n
+  trade_model_movement_list = [q for q in result]\n
+\n
+if src__:\n
+  return \'\\n\'.join((normal_movement_list, trade_model_movement_list))\n
+movement_list = []\n
+for movement in normal_movement_list + trade_model_movement_list:\n
+  movement = movement.getObject()\n
+  if movement.getDeliveryValue() is None :\n
+    if movement not in movement_list:\n
+      movement_list.append(movement)\n
+  else :\n
+    from Products.ERP5Type.Log import log\n
+    log(script.getId(), "simulation movement %s should not have been selected !" % movement.getPath())\n
+\n
+return movement_list\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>invoice_portal_type, **kw</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>1</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>invoice_portal_type</string>
+                            <string>kw</string>
+                            <string>invoice_portal_type_mapping</string>
+                            <string>_getattr_</string>
+                            <string>src__</string>
+                            <string>search_kw</string>
+                            <string>_write_</string>
+                            <string>_getitem_</string>
+                            <string>_apply_</string>
+                            <string>context</string>
+                            <string>result</string>
+                            <string>normal_movement_list</string>
+                            <string>append</string>
+                            <string>$append0</string>
+                            <string>_getiter_</string>
+                            <string>q</string>
+                            <string>trade_model_movement_list</string>
+                            <string>movement_list</string>
+                            <string>movement</string>
+                            <string>None</string>
+                            <string>Products.ERP5Type.Log</string>
+                            <string>log</string>
+                            <string>script</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>InvoiceTransaction_selectInvoiceMovement</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectPackingListMovement.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectPackingListMovement.xml
new file mode 100644
index 0000000000..6493ac20a4
--- /dev/null
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/InvoiceTransaction_selectPackingListMovement.xml
@@ -0,0 +1,205 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </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>"""Selects all movements which shall be built onto Sale Invoice"""\n
+invoice_portal_type_mapping = {\n
+  \'Sale Invoice Transaction\': [\n
+    [\'Sale Order\', \'Sale Packing List\'],\n
+    [\'started\', \'stopped\', \'delivered\']\n
+  ],\n
+  \'Purchase Invoice Transaction\': [\n
+    [\'Purchase Order\', \'Purchase Packing List\'],\n
+    [\'stopped\', \'delivered\']\n
+  ]\n
+}\n
+\n
+# XXX: Name is wrong\n
+# XXX: Causality Movement Group on builder splits those to two invoices\n
+src__ = kw.get(\'src__\',0)\n
+\n
+delivery_simulation_state_list = invoice_portal_type_mapping[invoice_portal_type][1]\n
+explanation_portal_type_list = invoice_portal_type_mapping[invoice_portal_type][0]\n
+\n
+search_kw = kw.copy()\n
+\n
+search_kw[\'parent_specialise_portal_type\']  = \'Invoicing Rule\'\n
+search_kw[\'explanation_portal_type\']        = explanation_portal_type_list\n
+search_kw[\'portal_type\']                    = \'Simulation Movement\'\n
+search_kw[\'grand_parent_simulation_state\']  = delivery_simulation_state_list\n
+\n
+search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
+\n
+result = context.InvoiceTransaction_zSelectMovement(**search_kw)\n
+if src__:\n
+  normal_movement_list = result\n
+else:\n
+  normal_movement_list = [q for q in result]\n
+\n
+search_kw = kw.copy()\n
+search_kw[\'parent_specialise_portal_type\']  = \'Trade Model Rule\'\n
+search_kw[\'explanation_portal_type\']        = explanation_portal_type_list\n
+search_kw[\'portal_type\']                    = \'Simulation Movement\'\n
+search_kw[\'grand_grand_grand_parent_simulation_state\']  = delivery_simulation_state_list\n
+\n
+search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
+\n
+result = context.InvoiceTransaction_zSelectMovement(**search_kw)\n
+if src__:\n
+  trade_movement_list = result\n
+else:\n
+  trade_movement_list = [q for q in result]\n
+\n
+if src__:\n
+  return \'\\n\'.join((normal_movement_list,trade_movement_list))\n
+\n
+movement_list = []\n
+for movement in normal_movement_list + trade_movement_list:\n
+  movement = movement.getObject()\n
+  if movement.getDeliveryValue() is None :\n
+    movement_list.append(movement)\n
+  else :\n
+    from Products.ERP5Type.Log import log\n
+    log("SaleInvoice_selectPackingListMovement", \\\n
+        "simulation movement %s should not have been selected !" % movement.getPath())\n
+\n
+return movement_list\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>invoice_portal_type, **kw</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>1</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>invoice_portal_type</string>
+                            <string>kw</string>
+                            <string>invoice_portal_type_mapping</string>
+                            <string>_getattr_</string>
+                            <string>src__</string>
+                            <string>_getitem_</string>
+                            <string>delivery_simulation_state_list</string>
+                            <string>explanation_portal_type_list</string>
+                            <string>search_kw</string>
+                            <string>_write_</string>
+                            <string>_apply_</string>
+                            <string>context</string>
+                            <string>result</string>
+                            <string>normal_movement_list</string>
+                            <string>append</string>
+                            <string>$append0</string>
+                            <string>_getiter_</string>
+                            <string>q</string>
+                            <string>trade_movement_list</string>
+                            <string>movement_list</string>
+                            <string>movement</string>
+                            <string>None</string>
+                            <string>Products.ERP5Type.Log</string>
+                            <string>log</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>InvoiceTransaction_selectPackingListMovement</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectInvoiceMovement.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectInvoiceMovement.xml
new file mode 100644
index 0000000000..e9145baf94
--- /dev/null
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectInvoiceMovement.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </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>return context.InvoiceTransaction_selectInvoiceMovement(\'Purchase Invoice Transaction\',**kw)\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>**kw</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>kw</string>
+                            <string>_apply_</string>
+                            <string>_getattr_</string>
+                            <string>context</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>PurchaseInvoiceTransaction_selectInvoiceMovement</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectPackingListMovement.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectPackingListMovement.xml
index fa1b938912..2e09ca8dee 100644
--- a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectPackingListMovement.xml
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/PurchaseInvoiceTransaction_selectPackingListMovement.xml
@@ -53,39 +53,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>"""Selects all movements which shall be built onto Purchase Invoice"""\n
-# XXX: Name is wrong\n
-# XXX: Causality Movement Group on builder splits those to two invoices\n
-search_kw = kw.copy()\n
-\n
-search_kw[\'parent_specialise_portal_type\']  = \'Invoicing Rule\'\n
-search_kw[\'explanation_portal_type\']        = [\'Purchase Order\', \'Purchase Packing List\']\n
-search_kw[\'portal_type\']                    = \'Simulation Movement\'\n
-search_kw[\'grand_parent_simulation_state\']  = [\'started\', \'stopped\',\'delivered\']\n
-\n
-search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
-normal_movement_list = [q for q in context.InvoiceTransaction_zSelectMovement(**search_kw)]\n
-search_kw = kw.copy()\n
-search_kw[\'parent_specialise_portal_type\']  = \'Trade Model Rule\'\n
-search_kw[\'explanation_portal_type\']        = [\'Purchase Order\', \'Purchase Packing List\']\n
-search_kw[\'portal_type\']                    = \'Simulation Movement\'\n
-search_kw[\'grand_parent_simulation_state\']  = [\'planned\',]\n
-\n
-search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
-\n
-trade_movement_list = [q for q in context.InvoiceTransaction_zSelectMovement(**search_kw)]\n
-\n
-movement_list = []\n
-for movement in normal_movement_list + trade_movement_list:\n
-  movement = movement.getObject()\n
-  if movement.getDeliveryValue() is None :\n
-    movement_list.append(movement)\n
-  else :\n
-    from Products.ERP5Type.Log import log\n
-    log("PurchaseInvoice_selectPackingListMovement", \\\n
-        "simulation movement %s should not have been selected !" % movement.getPath())\n
-\n
-return movement_list\n
+            <value> <string>return context.InvoiceTransaction_selectPackingListMovement(\'Purchase Invoice Transaction\',**kw)\n
 </string> </value>
         </item>
         <item>
@@ -123,22 +91,9 @@ return movement_list\n
                         <value>
                           <tuple>
                             <string>kw</string>
-                            <string>_getattr_</string>
-                            <string>search_kw</string>
-                            <string>_write_</string>
                             <string>_apply_</string>
+                            <string>_getattr_</string>
                             <string>context</string>
-                            <string>append</string>
-                            <string>$append0</string>
-                            <string>_getiter_</string>
-                            <string>q</string>
-                            <string>normal_movement_list</string>
-                            <string>trade_movement_list</string>
-                            <string>movement_list</string>
-                            <string>movement</string>
-                            <string>None</string>
-                            <string>Products.ERP5Type.Log</string>
-                            <string>log</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectInvoiceMovement.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectInvoiceMovement.xml
new file mode 100644
index 0000000000..754c8177c3
--- /dev/null
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectInvoiceMovement.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </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>return context.InvoiceTransaction_selectInvoiceMovement(\'Sale Invoice Transaction\',**kw)\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>**kw</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>kw</string>
+                            <string>_apply_</string>
+                            <string>_getattr_</string>
+                            <string>context</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>SaleInvoiceTransaction_selectInvoiceMovement</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectPackingListMovement.xml b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectPackingListMovement.xml
index 544e677c07..231ae7dccb 100644
--- a/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectPackingListMovement.xml
+++ b/bt5/erp5_bpm/SkinTemplateItem/portal_skins/erp5_bpm/SaleInvoiceTransaction_selectPackingListMovement.xml
@@ -53,39 +53,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>"""Selects all movements which shall be built onto Sale Invoice"""\n
-# XXX: Name is wrong\n
-# XXX: Causality Movement Group on builder splits those to two invoices\n
-search_kw = kw.copy()\n
-\n
-search_kw[\'parent_specialise_portal_type\']  = \'Invoicing Rule\'\n
-search_kw[\'explanation_portal_type\']        = [\'Sale Order\', \'Sale Packing List\']\n
-search_kw[\'portal_type\']                    = \'Simulation Movement\'\n
-search_kw[\'grand_parent_simulation_state\']  = [\'started\', \'stopped\',\'delivered\']\n
-\n
-search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
-normal_movement_list = [q for q in context.InvoiceTransaction_zSelectMovement(**search_kw)]\n
-search_kw = kw.copy()\n
-search_kw[\'parent_specialise_portal_type\']  = \'Trade Model Rule\'\n
-search_kw[\'explanation_portal_type\']        = [\'Sale Order\', \'Sale Packing List\']\n
-search_kw[\'portal_type\']                    = \'Simulation Movement\'\n
-search_kw[\'grand_parent_simulation_state\']  = [\'planned\',]\n
-\n
-search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
-\n
-trade_movement_list = [q for q in context.InvoiceTransaction_zSelectMovement(**search_kw)]\n
-\n
-movement_list = []\n
-for movement in normal_movement_list + trade_movement_list:\n
-  movement = movement.getObject()\n
-  if movement.getDeliveryValue() is None :\n
-    movement_list.append(movement)\n
-  else :\n
-    from Products.ERP5Type.Log import log\n
-    log("SaleInvoice_selectPackingListMovement", \\\n
-        "simulation movement %s should not have been selected !" % movement.getPath())\n
-\n
-return movement_list\n
+            <value> <string>return context.InvoiceTransaction_selectPackingListMovement(\'Sale Invoice Transaction\',**kw)\n
 </string> </value>
         </item>
         <item>
@@ -123,22 +91,9 @@ return movement_list\n
                         <value>
                           <tuple>
                             <string>kw</string>
-                            <string>_getattr_</string>
-                            <string>search_kw</string>
-                            <string>_write_</string>
                             <string>_apply_</string>
+                            <string>_getattr_</string>
                             <string>context</string>
-                            <string>append</string>
-                            <string>$append0</string>
-                            <string>_getiter_</string>
-                            <string>q</string>
-                            <string>normal_movement_list</string>
-                            <string>trade_movement_list</string>
-                            <string>movement_list</string>
-                            <string>movement</string>
-                            <string>None</string>
-                            <string>Products.ERP5Type.Log</string>
-                            <string>log</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_bpm/bt/revision b/bt5/erp5_bpm/bt/revision
index b00047941a..9da06a1833 100644
--- a/bt5/erp5_bpm/bt/revision
+++ b/bt5/erp5_bpm/bt/revision
@@ -1 +1 @@
-159
\ No newline at end of file
+160
\ No newline at end of file
-- 
2.30.9