From c43f89ae12cf9cd906baa2d5a044d0ac8fb8d84c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Wed, 1 Jul 2009 13:50:03 +0000
Subject: [PATCH]  - to avoid code duplication use common script

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27851 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...voiceTransaction_selectInvoiceMovement.xml | 156 ++++++++++++++++++
 ...voiceTransaction_selectInvoiceMovement.xml |  31 +---
 ...voiceTransaction_selectInvoiceMovement.xml |  31 +---
 bt5/erp5_invoicing/bt/revision                |   2 +-
 4 files changed, 161 insertions(+), 59 deletions(-)
 create mode 100644 bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/InvoiceTransaction_selectInvoiceMovement.xml

diff --git a/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/InvoiceTransaction_selectInvoiceMovement.xml b/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/InvoiceTransaction_selectInvoiceMovement.xml
new file mode 100644
index 0000000000..9da52a484a
--- /dev/null
+++ b/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/InvoiceTransaction_selectInvoiceMovement.xml
@@ -0,0 +1,156 @@
+<?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>kw[\'parent_specialise_portal_type\'] = \'Invoice Transaction Rule\'\n
+if context.Invoice_isAdvanced():\n
+  kw[\'explanation_portal_type\']       = [\'%s Order\' % trade_type,\n
+                                         \'%s Invoice\' % trade_type,\n
+                                         \'%s Packing List\' % trade_type]\n
+else:\n
+  kw[\'explanation_portal_type\']       = [\'%s Order\' % trade_type,\n
+                                         \'%s Invoice Transaction\' % trade_type,\n
+                                         \'%s Packing List\' % trade_type]\n
+kw[\'portal_type\']                   = \'Simulation Movement\'\n
+kw[\'grand_parent_simulation_state\'] = [\'started\']\n
+\n
+kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
+\n
+movement_list = [] \n
+for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\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(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>trade_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>trade_type</string>
+                            <string>kw</string>
+                            <string>_write_</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>_apply_</string>
+                            <string>movement_list</string>
+                            <string>_getiter_</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>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/PurchaseInvoiceTransaction_selectInvoiceMovement.xml b/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/PurchaseInvoiceTransaction_selectInvoiceMovement.xml
index 663864157d..2370fb5a1c 100644
--- a/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/PurchaseInvoiceTransaction_selectInvoiceMovement.xml
+++ b/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/PurchaseInvoiceTransaction_selectInvoiceMovement.xml
@@ -53,26 +53,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>kw[\'parent_specialise_portal_type\'] = \'Invoice Transaction Rule\'\n
-if context.Invoice_isAdvanced():\n
-  kw[\'explanation_portal_type\']     = [\'Purchase Order\', \'Purchase Invoice\', \'Purchase Packing List\']\n
-else:\n
-  kw[\'explanation_portal_type\']     = [\'Purchase Order\', \'Purchase Invoice Transaction\', \'Purchase Packing List\']\n
-kw[\'portal_type\']                   = \'Simulation Movement\'\n
-kw[\'grand_parent_simulation_state\'] = [\'started\']\n
-\n
-kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
-\n
-movement_list = [] \n
-for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\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(script.getId(), "simulation movement %s should not have been selected !" % movement.getPath())\n
-\n
-return movement_list\n
+            <value> <string>return context.InvoiceTransaction_selectInvoiceMovement(trade_type=\'Purchase\', **kw)\n
 </string> </value>
         </item>
         <item>
@@ -110,17 +91,9 @@ return movement_list\n
                         <value>
                           <tuple>
                             <string>kw</string>
-                            <string>_write_</string>
+                            <string>_apply_</string>
                             <string>_getattr_</string>
                             <string>context</string>
-                            <string>_apply_</string>
-                            <string>movement_list</string>
-                            <string>_getiter_</string>
-                            <string>movement</string>
-                            <string>None</string>
-                            <string>Products.ERP5Type.Log</string>
-                            <string>log</string>
-                            <string>script</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/SaleInvoiceTransaction_selectInvoiceMovement.xml b/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/SaleInvoiceTransaction_selectInvoiceMovement.xml
index 6643294485..58bf4aeb79 100644
--- a/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/SaleInvoiceTransaction_selectInvoiceMovement.xml
+++ b/bt5/erp5_invoicing/SkinTemplateItem/portal_skins/erp5_invoicing/SaleInvoiceTransaction_selectInvoiceMovement.xml
@@ -53,26 +53,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>kw[\'parent_specialise_portal_type\'] = \'Invoice Transaction Rule\'\n
-if context.Invoice_isAdvanced():\n
-  kw[\'explanation_portal_type\']       = [\'Sale Order\', \'Sale Invoice\', \'Sale Packing List\']\n
-else:\n
-  kw[\'explanation_portal_type\']       = [\'Sale Order\', \'Sale Invoice Transaction\', \'Sale Packing List\']\n
-kw[\'portal_type\']                   = \'Simulation Movement\'\n
-kw[\'grand_parent_simulation_state\'] = [\'started\']\n
-\n
-kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
-\n
-movement_list = [] \n
-for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\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(script.getId(), "simulation movement %s should not have been selected !" % movement.getPath())\n
-\n
-return movement_list\n
+            <value> <string>return context.InvoiceTransaction_selectInvoiceMovement(trade_type=\'Sale\', **kw)\n
 </string> </value>
         </item>
         <item>
@@ -110,17 +91,9 @@ return movement_list\n
                         <value>
                           <tuple>
                             <string>kw</string>
-                            <string>_write_</string>
+                            <string>_apply_</string>
                             <string>_getattr_</string>
                             <string>context</string>
-                            <string>_apply_</string>
-                            <string>movement_list</string>
-                            <string>_getiter_</string>
-                            <string>movement</string>
-                            <string>None</string>
-                            <string>Products.ERP5Type.Log</string>
-                            <string>log</string>
-                            <string>script</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_invoicing/bt/revision b/bt5/erp5_invoicing/bt/revision
index cb16690c5e..8a32cf7839 100644
--- a/bt5/erp5_invoicing/bt/revision
+++ b/bt5/erp5_invoicing/bt/revision
@@ -1 +1 @@
-249
\ No newline at end of file
+250
\ No newline at end of file
-- 
2.30.9