From 67f61b3d4e76602456a82a641ae6a2b4462e24a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Wed, 18 Oct 2006 08:08:32 +0000
Subject: [PATCH] many fix in wf scripts : more check, use fast=0 fro
 getTotalPrice and typo

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10795 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../scripts/validateBalance.xml               |   4 +-
 .../scripts/validateSourceAndDestination.xml  | 154 ++++++++++++++++++
 .../transitions/deliver.xml                   |   2 +-
 .../scripts/validateVaultBalance.xml          |   6 +-
 .../scripts/CheckTransitionDeliver.xml        |   2 +-
 .../scripts/checkConsistency.xml              |  42 ++++-
 .../scripts/validateVaultBalance.xml          |   9 +-
 .../states/confirmed.xml                      |   2 -
 .../transitions/cancel.xml                    |   2 +-
 .../transitions/cancel_action.xml             |   2 +-
 .../scripts/validateVaultBalance.xml          |  10 +-
 11 files changed, 220 insertions(+), 15 deletions(-)
 create mode 100644 bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateSourceAndDestination.xml

diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateBalance.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateBalance.xml
index 9d2baeaa68..d92b3e8129 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateBalance.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateBalance.xml
@@ -79,8 +79,8 @@ resource =  transaction.CashDelivery_checkCounterInventory(source=vault, portal_
 \n
 # Get price and total_price.\n
 price = transaction.getSourceTotalAssetPrice()\n
-input_cash = transaction.getTotalPrice(deliveryLineType=\'Incoming Cash Sorting Line\')\n
-output_cash = transaction.getTotalPrice(deliveryLineType=\'Outgoing Cash Sorting Line\')\n
+input_cash = transaction.getTotalPrice(fast=0,portal_type=(\'Incoming Cash Sorting Line\',\'Cash Delivery Cell\'))\n
+output_cash = transaction.getTotalPrice(fast=0,portal_type=(\'Outgoing Cash Sorting Line\',\'Cash Delivery Cell\'))\n
 \n
 if input_cash != output_cash :\n
   msg=Message(domain="ui", message="Incoming cash amount is different from outgoing cash amount.")\n
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateSourceAndDestination.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateSourceAndDestination.xml
new file mode 100644
index 0000000000..366cb85cea
--- /dev/null
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/scripts/validateSourceAndDestination.xml
@@ -0,0 +1,154 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <tuple>
+          <string>Products.PythonScripts.PythonScript</string>
+          <string>PythonScript</string>
+        </tuple>
+        <none/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Python_magic</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </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>transaction = state_change.object\n
+\n
+# Check getBaobabSource and getBaobabDestination\n
+transaction.Base_checkBaobabSourceAndDestination()\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_filepath</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_owner</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>state_change, **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>state_change</string>
+                            <string>kw</string>
+                            <string>_getattr_</string>
+                            <string>transaction</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>validateSourceAndDestination</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/transitions/deliver.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/transitions/deliver.xml
index 1af33ab1af..35125492fc 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/transitions/deliver.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_sorting_workflow/transitions/deliver.xml
@@ -60,7 +60,7 @@
         </item>
         <item>
             <key> <string>script_name</string> </key>
-            <value> <string></string> </value>
+            <value> <string>validateSourceAndDestination</string> </value>
         </item>
         <item>
             <key> <string>title</string> </key>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_to_currency_sale_workflow/scripts/validateVaultBalance.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_to_currency_sale_workflow/scripts/validateVaultBalance.xml
index d54270de49..a7775b587f 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_to_currency_sale_workflow/scripts/validateVaultBalance.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/cash_to_currency_sale_workflow/scripts/validateVaultBalance.xml
@@ -98,8 +98,10 @@ if not transaction.Baobab_checkCounterDateOpen(site=outgoing_source, date=transa
 resource_one = transaction.CashDelivery_checkCounterInventory(outgoing_source,portal_type=\'Outgoing Cash To Currency Sale Line\')\n
 \n
 \n
-billetage_entre = transaction.getTotalPrice(deliveryLineType=\'Incoming Cash To Currency Sale Line\')\n
-billetage_sorti = transaction.getTotalPrice(deliveryLineType=\'Outgoing Cash To Currency Sale Line\')\n
+#billetage_entre = transaction.getTotalPrice(deliveryLineType=\'Incoming Cash To Currency Sale Line\')\n
+billetage_entre = transaction.getTotalPrice(portal_type=[\'Incoming Cash To Currency Sale Line\',\'Cash Delivery Cell\'],fast=0)\n
+#billetage_sorti = transaction.getTotalPrice(deliveryLineType=\'Outgoing Cash To Currency Sale Line\')\n
+billetage_sorti = transaction.getTotalPrice(portal_type=[\'Outgoing Cash To Currency Sale Line\', \'Cash Delivery Cell\'],fast=0)\n
 \n
 \n
 base_price = transaction.getSourceTotalAssetPrice()\n
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/mutilated_banknote_workflow/scripts/CheckTransitionDeliver.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/mutilated_banknote_workflow/scripts/CheckTransitionDeliver.xml
index 91fa9afea0..5ada8465bf 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/mutilated_banknote_workflow/scripts/CheckTransitionDeliver.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/mutilated_banknote_workflow/scripts/CheckTransitionDeliver.xml
@@ -76,7 +76,7 @@ from Products.ERP5Type.Message import Message\n
 ob = state_change[\'object\']\n
 state = ob.getSimulationState()\n
 # only \'siege\' can do this when no pay back\n
-if  state == "planned":\n
+if state == "planned":\n
   if ob.getTotalPrice(portal_type="Exchanged Mutilated Banknote Line", fast=0) != 0:\n
     # we must be in \'siege\' and we want to pay back for another site\n
     if \'siege\' not in ob.getSource() or ob.getSource() == ob.getSourceTrade():\n
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_incident_workflow/scripts/checkConsistency.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_incident_workflow/scripts/checkConsistency.xml
index 5848960445..c50f5ce08c 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_incident_workflow/scripts/checkConsistency.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_incident_workflow/scripts/checkConsistency.xml
@@ -73,8 +73,14 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
 from Products.ERP5Type.Message import Message\n
 \n
 txn = state_change[\'object\']\n
-in_list = txn.searchFolder(portal_type=\'Incoming Usual Cash Incident Line\')\n
-out_list = txn.searchFolder(portal_type=\'Outgoing Usual Cash Incident Line\')\n
+in_list = txn.objectValues(portal_type=\'Incoming Usual Cash Incident Line\')\n
+out_list = txn.objectValues(portal_type=\'Outgoing Usual Cash Incident Line\')\n
+\n
+var_type =txn.getIncidentType()\n
+var_source_transport =txn.getSourceTransport()\n
+if (var_type == \'reception\' and var_source_transport is None):\n
+   msg = Message(domain = "ui", message="Remote Site not null.")\n
+   raise ValidationFailed, (msg,)\n
 \n
 price = txn.getSourceTotalAssetPrice()\n
 in_price = txn.getTotalPrice(deliveryLineType=\'Incoming Usual Cash Incident Line\')\n
@@ -97,6 +103,12 @@ elif (in_price != 0 and in_price != price) or (out_price != 0 and out_price != p
               <none/>
             </value>
         </item>
+        <item>
+            <key> <string>_dav_writelocks</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+            </value>
+        </item>
         <item>
             <key> <string>_filepath</string> </key>
             <value>
@@ -141,11 +153,14 @@ elif (in_price != 0 and in_price != price) or (out_price != 0 and out_price != p
                             <string>_getattr_</string>
                             <string>in_list</string>
                             <string>out_list</string>
+                            <string>var_type</string>
+                            <string>var_source_transport</string>
+                            <string>None</string>
+                            <string>msg</string>
                             <string>price</string>
                             <string>in_price</string>
                             <string>out_price</string>
                             <string>len</string>
-                            <string>msg</string>
                           </tuple>
                         </value>
                     </item>
@@ -173,4 +188,25 @@ elif (in_price != 0 and in_price != price) or (out_price != 0 and out_price != p
       </dictionary>
     </pickle>
   </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <tuple>
+        <tuple>
+          <string>Persistence</string>
+          <string>PersistentMapping</string>
+        </tuple>
+        <none/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_container</string> </key>
+            <value>
+              <dictionary/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
 </ZopeData>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/scripts/validateVaultBalance.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/scripts/validateVaultBalance.xml
index 49cb928bcb..d72af1c877 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/scripts/validateVaultBalance.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/scripts/validateVaultBalance.xml
@@ -74,9 +74,15 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
 from Products.ERP5Type.Message import Message\n
 \n
 transaction = state_change.object\n
-\n
+date = transaction.getStartDate()\n
 vault = transaction.getSource()\n
 vaultDestination = transaction.getDestination()\n
+\n
+# check we are in an opened accounting day\n
+if not transaction.Baobab_checkCounterDateOpen(site=vault, date=date):\n
+  msg = Message(domain = "ui", message="Counter Date is not opened")\n
+  raise ValidationFailed, (msg,)\n
+\n
 if \'reserve\' in vault and \'salle_tri\' in vaultDestination:\n
   msg = Message(domain="ui", message="Cannot transfer ressource to ${destination} from ${source}.",\n
                 mapping={\'source\':transaction.getSourceValue().getParentValue().getTitle(),\n
@@ -149,6 +155,7 @@ elif resource <> 0 :\n
                             <string>Message</string>
                             <string>_getattr_</string>
                             <string>transaction</string>
+                            <string>date</string>
                             <string>vault</string>
                             <string>vaultDestination</string>
                             <string>msg</string>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/states/confirmed.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/states/confirmed.xml
index bb62817ec6..548e0ca7be 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/states/confirmed.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_rendering_workflow/states/confirmed.xml
@@ -42,8 +42,6 @@
               <tuple>
                 <string>deliver</string>
                 <string>deliver_action</string>
-                <string>reject</string>
-                <string>reject_action</string>
               </tuple>
             </value>
         </item>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel.xml
index 4846ec69db..c556c28ce4 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel.xml
@@ -89,7 +89,7 @@
             <key> <string>roles</string> </key>
             <value>
               <tuple>
-                <string>Assignee</string>
+                <string>Assignor</string>
                 <string>Manager</string>
               </tuple>
             </value>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel_action.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel_action.xml
index 5460389592..700818f326 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel_action.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/usual_cash_transfer_workflow/transitions/cancel_action.xml
@@ -89,7 +89,7 @@
             <key> <string>roles</string> </key>
             <value>
               <tuple>
-                <string>Assignee</string>
+                <string>Assignor</string>
                 <string>Manager</string>
               </tuple>
             </value>
diff --git a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/vault_transfer_workflow/scripts/validateVaultBalance.xml b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/vault_transfer_workflow/scripts/validateVaultBalance.xml
index 49cb928bcb..ff54cf9dfe 100644
--- a/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/vault_transfer_workflow/scripts/validateVaultBalance.xml
+++ b/bt5/erp5_banking_cash/WorkflowTemplateItem/portal_workflow/vault_transfer_workflow/scripts/validateVaultBalance.xml
@@ -74,9 +74,16 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
 from Products.ERP5Type.Message import Message\n
 \n
 transaction = state_change.object\n
-\n
+date = transaction.getStartDate()\n
 vault = transaction.getSource()\n
 vaultDestination = transaction.getDestination()\n
+\n
+# check we are in an opened accounting day\n
+if not transaction.Baobab_checkCounterDateOpen(site=vaultDestination, date=date):\n
+  msg = Message(domain = "ui", message="Counter Date is not opened")\n
+  raise ValidationFailed, (msg,)\n
+\n
+\n
 if \'reserve\' in vault and \'salle_tri\' in vaultDestination:\n
   msg = Message(domain="ui", message="Cannot transfer ressource to ${destination} from ${source}.",\n
                 mapping={\'source\':transaction.getSourceValue().getParentValue().getTitle(),\n
@@ -149,6 +156,7 @@ elif resource <> 0 :\n
                             <string>Message</string>
                             <string>_getattr_</string>
                             <string>transaction</string>
+                            <string>date</string>
                             <string>vault</string>
                             <string>vaultDestination</string>
                             <string>msg</string>
-- 
2.30.9