From d730e0b625cf2fddbee154b9dfac50ef37649de9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 20 Dec 2012 11:19:36 +0100
Subject: [PATCH] erp5_accounting: reorganise init scripts and do not
 initialise some accounting lines if the user is allowed to add invoice lines.

---
 .../AccountingTransaction_init.xml            | 12 ++--
 ...ountingTransaction_initFromPreferences.xml | 70 -------------------
 .../InternalInvoiceTransaction_init.xml       | 19 ++---
 .../PaymentTransaction_init.xml               | 20 +++---
 .../PurchaseInvoiceTransaction_init.xml       | 27 ++++---
 .../SaleInvoiceTransaction_init.xml           | 23 +++---
 bt5/erp5_accounting/bt/revision               |  2 +-
 7 files changed, 48 insertions(+), 125 deletions(-)
 delete mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_initFromPreferences.xml

diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_init.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_init.xml
index 22b415339b..4d7275e56f 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_init.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_init.xml
@@ -50,15 +50,15 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>transaction = context\n
-\n
-if kw.get(\'created_by_builder\', 0): \n
+            <value> <string>if kw.get(\'created_by_builder\', 0): \n
   return\n
 \n
-transaction.newContent(portal_type=\'Accounting Transaction Line\', )\n
-transaction.newContent(portal_type=\'Accounting Transaction Line\', )\n
+preference_tool = context.getPortalObject().portal_preferences\n
+context.setSourceSection(preference_tool.getPreferredAccountingTransactionSourceSection())\n
+context.setResource(preference_tool.getPreferredAccountingTransactionCurrency())\n
 \n
-context.AccountingTransaction_initFromPreferences()\n
+context.newContent(portal_type=\'Accounting Transaction Line\', )\n
+context.newContent(portal_type=\'Accounting Transaction Line\', )\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_initFromPreferences.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_initFromPreferences.xml
deleted file mode 100644
index 0d7463b8f5..0000000000
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_initFromPreferences.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?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>preference_tool = context.getPortalObject().portal_preferences\n
-context.edit(\n
-    source_section = preference_tool.getPreferredAccountingTransactionSourceSection(),\n
-    resource = preference_tool.getPreferredAccountingTransactionCurrency())\n
-</string> </value>
-        </item>
-        <item>
-            <key> <string>_params</string> </key>
-            <value> <string></string> </value>
-        </item>
-        <item>
-            <key> <string>id</string> </key>
-            <value> <string>AccountingTransaction_initFromPreferences</string> </value>
-        </item>
-      </dictionary>
-    </pickle>
-  </record>
-</ZopeData>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/InternalInvoiceTransaction_init.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/InternalInvoiceTransaction_init.xml
index 371ef5577d..8cbcdbafe5 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/InternalInvoiceTransaction_init.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/InternalInvoiceTransaction_init.xml
@@ -50,22 +50,15 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>transaction = context\n
-\n
-if kw.get(\'created_by_builder\', 0): \n
+            <value> <string>if kw.get(\'created_by_builder\', 0): \n
   return\n
 \n
-transaction.newContent(portal_type=\'Internal Invoice Transaction Line\', )\n
-transaction.newContent(portal_type=\'Internal Invoice Transaction Line\', )\n
-\n
-from Products.CMFCore.utils import getToolByName\n
-\n
-transaction = context\n
-preference_tool = getToolByName(context, \'portal_preferences\')\n
+preference_tool = context.getPortalObject().portal_preferences\n
+context.setSourceSection(preference_tool.getPreferredAccountingTransactionSourceSection())\n
+context.setResource(preference_tool.getPreferredAccountingTransactionCurrency())\n
 \n
-transaction.edit (\n
-    source_section = preference_tool.getPreferredAccountingTransactionSourceSection(),\n
-    resource = preference_tool.getPreferredAccountingTransactionCurrency())\n
+context.newContent(portal_type=\'Internal Invoice Transaction Line\', )\n
+context.newContent(portal_type=\'Internal Invoice Transaction Line\', )\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PaymentTransaction_init.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PaymentTransaction_init.xml
index f61b037978..b85b13fac3 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PaymentTransaction_init.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PaymentTransaction_init.xml
@@ -50,19 +50,19 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>transaction = context\n
-\n
-if kw.get(\'created_by_builder\', 0): \n
+            <value> <string>if kw.get(\'created_by_builder\', 0): \n
   return\n
 \n
-transaction.newContent(portal_type=\'Accounting Transaction Line\',\n
-                       id=\'receivable\', )\n
-transaction.newContent(portal_type=\'Accounting Transaction Line\',\n
-                       id=\'payable\', )\n
-transaction.newContent(portal_type=\'Accounting Transaction Line\',\n
-                       id=\'bank\', )\n
+preference_tool = context.getPortalObject().portal_preferences\n
+context.setSourceSection(preference_tool.getPreferredAccountingTransactionSourceSection())\n
+context.setResource(preference_tool.getPreferredAccountingTransactionCurrency())\n
 \n
-context.AccountingTransaction_initFromPreferences()\n
+context.newContent(portal_type=\'Accounting Transaction Line\',\n
+                   id=\'receivable\')\n
+context.newContent(portal_type=\'Accounting Transaction Line\',\n
+                   id=\'payable\')\n
+context.newContent(portal_type=\'Accounting Transaction Line\',\n
+                   id=\'bank\')\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_init.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_init.xml
index 32d87f65f5..687b26f9b4 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_init.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_init.xml
@@ -50,25 +50,22 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>transaction = context\n
-\n
-if kw.get(\'created_by_builder\', 0): \n
+            <value> <string>if kw.get(\'created_by_builder\', 0): \n
   return\n
 \n
-from Products.CMFCore.utils import getToolByName\n
-preference_tool = getToolByName(context, \'portal_preferences\')\n
+preference_tool = context.getPortalObject().portal_preferences\n
+context.setDestinationSection(preference_tool.getPreferredAccountingTransactionSourceSection())\n
+context.setResource(preference_tool.getPreferredAccountingTransactionCurrency())\n
 \n
-transaction.edit (\n
-     # XXX getPreferredAccountingTransactionSourceSection is definitively a bad name ...\n
-    destination_section = preference_tool.getPreferredAccountingTransactionSourceSection(),\n
-    resource = preference_tool.getPreferredAccountingTransactionCurrency())\n
+if \'Invoice Line\' in context.getVisibleAllowedContentTypeList():\n
+  return\n
 \n
-transaction.newContent(portal_type=\'Purchase Invoice Transaction Line\',\n
-                       id=\'expense\', )\n
-transaction.newContent(portal_type=\'Purchase Invoice Transaction Line\',\n
-                       id=\'payable\', )\n
-transaction.newContent(portal_type=\'Purchase Invoice Transaction Line\',\n
-                       id=\'refundable_vat\', )\n
+context.newContent(portal_type=\'Purchase Invoice Transaction Line\',\n
+                   id=\'expense\', )\n
+context.newContent(portal_type=\'Purchase Invoice Transaction Line\',\n
+                   id=\'payable\', )\n
+context.newContent(portal_type=\'Purchase Invoice Transaction Line\',\n
+                   id=\'refundable_vat\', )\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_init.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_init.xml
index f5cf7b7e50..cd08d6d57a 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_init.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_init.xml
@@ -50,19 +50,22 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>transaction = context\n
-\n
-if kw.get(\'created_by_builder\', 0): \n
+            <value> <string>if kw.get(\'created_by_builder\', 0): \n
   return\n
 \n
-transaction.newContent(portal_type=\'Sale Invoice Transaction Line\',\n
-                       id=\'income\',)\n
-transaction.newContent(portal_type=\'Sale Invoice Transaction Line\',\n
-                       id=\'receivable\', )\n
-transaction.newContent(portal_type=\'Sale Invoice Transaction Line\',\n
-                       id=\'collected_vat\',)\n
+preference_tool = context.getPortalObject().portal_preferences\n
+context.setSourceSection(preference_tool.getPreferredAccountingTransactionSourceSection())\n
+context.setResource(preference_tool.getPreferredAccountingTransactionCurrency())\n
+    \n
+if \'Invoice Line\' in context.getVisibleAllowedContentTypeList():\n
+  return\n
 \n
-context.AccountingTransaction_initFromPreferences()\n
+context.newContent(portal_type=\'Sale Invoice Transaction Line\',\n
+                   id=\'income\',)\n
+context.newContent(portal_type=\'Sale Invoice Transaction Line\',\n
+                   id=\'receivable\', )\n
+context.newContent(portal_type=\'Sale Invoice Transaction Line\',\n
+                   id=\'collected_vat\',)\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision
index f0cec364da..24ec8a0c03 100644
--- a/bt5/erp5_accounting/bt/revision
+++ b/bt5/erp5_accounting/bt/revision
@@ -1 +1 @@
-1505
\ No newline at end of file
+1506
\ No newline at end of file
-- 
2.30.9