From f27afe4a3a928ec65b45087c8ff089ceeb0dc51b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Mon, 19 Nov 2007 10:30:40 +0000
Subject: [PATCH] 2007-11-19 Aurel * rewrite workflow script to do more check *
 modify sql method to manage case of no node or payment

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17678 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_archive/Archive_getNodeUidList.xml   | 40 +++++++-----
 .../Archive_getPaymentUidList.xml             | 32 ++++++----
 .../archive_workflow/scripts/checkArchive.xml | 63 +++++++++++++------
 bt5/erp5_archive/bt/change_log                |  3 +
 bt5/erp5_archive/bt/revision                  |  2 +-
 5 files changed, 92 insertions(+), 48 deletions(-)

diff --git a/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getNodeUidList.xml b/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getNodeUidList.xml
index a46c17ee3f..46ed9fa22c 100644
--- a/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getNodeUidList.xml
+++ b/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getNodeUidList.xml
@@ -133,14 +133,18 @@ account_node_uid</string> </value>
 select distinct(stock.node_uid) \n
 from stock \n
 where \n
-  (stock.payment_uid not in (\n
-   <dtml-in account_uid_list>\n
-    <dtml-unless sequence-start>, </dtml-unless>\n
-     <dtml-sqlvar sequence-item type="int">\n
-   </dtml-in>\n
-   ) \n
-  or stock.payment_uid is NULL\n
-  or stock.payment_uid = "")\n
+  (1)\n
+  <dtml-if account_uid_list>\n
+    or \n
+    (stock.payment_uid not in ( \n
+     <dtml-in account_uid_list>\n
+      <dtml-unless sequence-start>, </dtml-unless>\n
+       <dtml-sqlvar sequence-item type="int">\n
+     </dtml-in>\n
+     ) \n
+    or stock.payment_uid is NULL\n
+    or stock.payment_uid = "")\n
+  </dtml-if>\n
   <dtml-if account_node_uid>\n
     and stock.node_uid != <dtml-sqlvar account_node_uid type="int" >\n
   </dtml-if>
@@ -186,14 +190,18 @@ where \n
 select distinct(stock.node_uid) \n
 from stock \n
 where \n
-  (stock.payment_uid not in (\n
-   <dtml-in account_uid_list>\n
-    <dtml-unless sequence-start>, </dtml-unless>\n
-     <dtml-sqlvar sequence-item type="int">\n
-   </dtml-in>\n
-   ) \n
-  or stock.payment_uid is NULL\n
-  or stock.payment_uid = "")\n
+  (1)\n
+  <dtml-if account_uid_list>\n
+    or \n
+    (stock.payment_uid not in ( \n
+     <dtml-in account_uid_list>\n
+      <dtml-unless sequence-start>, </dtml-unless>\n
+       <dtml-sqlvar sequence-item type="int">\n
+     </dtml-in>\n
+     ) \n
+    or stock.payment_uid is NULL\n
+    or stock.payment_uid = "")\n
+  </dtml-if>\n
   <dtml-if account_node_uid>\n
     and stock.node_uid != <dtml-sqlvar account_node_uid type="int" >\n
   </dtml-if>
diff --git a/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getPaymentUidList.xml b/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getPaymentUidList.xml
index 5fbc65e3a5..970eade9e5 100644
--- a/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getPaymentUidList.xml
+++ b/bt5/erp5_archive/SkinTemplateItem/portal_skins/erp5_archive/Archive_getPaymentUidList.xml
@@ -125,12 +125,16 @@
 select distinct(stock.payment_uid) \n
 from stock \n
 where \n
-  stock.payment_uid in (\n
-   <dtml-in account_uid_list>\n
-    <dtml-unless sequence-start>, </dtml-unless>\n
-     <dtml-sqlvar sequence-item type="int">\n
-   </dtml-in>\n
-   ) \n
+  (1)\n
+  <dtml-if account_uid_list>\n
+    and\n
+    stock.payment_uid in (\n
+     <dtml-in account_uid_list>\n
+       <dtml-unless sequence-start>, </dtml-unless>\n
+       <dtml-sqlvar sequence-item type="int">\n
+     </dtml-in>\n
+     ) \n
+  </dtml-if>\n
   and stock.payment_uid is not NULL  \n
   and stock.payment_uid != ""
 
@@ -175,12 +179,16 @@ where \n
 select distinct(stock.payment_uid) \n
 from stock \n
 where \n
-  stock.payment_uid in (\n
-   <dtml-in account_uid_list>\n
-    <dtml-unless sequence-start>, </dtml-unless>\n
-     <dtml-sqlvar sequence-item type="int">\n
-   </dtml-in>\n
-   ) \n
+  (1)\n
+  <dtml-if account_uid_list>\n
+    and\n
+    stock.payment_uid in (\n
+     <dtml-in account_uid_list>\n
+       <dtml-unless sequence-start>, </dtml-unless>\n
+       <dtml-sqlvar sequence-item type="int">\n
+     </dtml-in>\n
+     ) \n
+  </dtml-if>\n
   and stock.payment_uid is not NULL  \n
   and stock.payment_uid != ""
 
diff --git a/bt5/erp5_archive/WorkflowTemplateItem/portal_workflow/archive_workflow/scripts/checkArchive.xml b/bt5/erp5_archive/WorkflowTemplateItem/portal_workflow/archive_workflow/scripts/checkArchive.xml
index e5bf1fa90a..82840b5a93 100644
--- a/bt5/erp5_archive/WorkflowTemplateItem/portal_workflow/archive_workflow/scripts/checkArchive.xml
+++ b/bt5/erp5_archive/WorkflowTemplateItem/portal_workflow/archive_workflow/scripts/checkArchive.xml
@@ -75,33 +75,58 @@ from Products.ERP5Type.Message import Message\n
 # Check connection definition\n
 \n
 archive = state_change[\'object\']\n
-min_stop_date = archive.getStopDateRangeMin()\n
+min_stop_date = archive.getStopDateRangeMin().Date()\n
 catalog_id = archive.getCatalogId()\n
 \n
 if "deferred" not in archive.getDeferredConnectionId():\n
   msg = Message(domain=\'ui\', message=\'Deferred connection ID choose is not a deferred connection.\')\n
   raise ValidationFailed, (msg,)\n
 \n
-previous_archive_list = [x.getObject() for x in archive.portal_catalog(portal_type="Archive", validation_state=\'validated\')]\n
-\n
 def sort_max_date(a, b):\n
   return cmp(a.getStopDateRangeMax(), b.getStopDateRangeMax())\n
-previous_archive_list.sort(sort_max_date)\n
 \n
-if len(previous_archive_list) > 0:\n
-  # Check the date\n
-  previous_archive = previous_archive_list[-1]\n
-  if previous_archive.getStopDateRangeMax() is None:\n
-    msg = Message(domain=\'ui\', message=\'No max stop date defined in previous archive.\')\n
-    raise ValidationFailed, (msg,)\n
-  if previous_archive.getStopDateRangeMax() + 1 != min_stop_date:\n
-    msg = Message(domain=\'ui\', message=\'Archive are not contiguous.\')\n
-    raise ValidationFailed, (msg,)\n
-  # Check the catalog\n
-  for arch in previous_archive_list:\n
-    if arch.getCatalogId() == catalog_id and arch is not previous_archive:\n
-      msg = Message(domain=\'ui\', message=\'Use of a former catalog is prohibited.\')\n
+\n
+if archive.getStopDateRangeMax() is not None:\n
+\n
+  previous_archive_list = [x.getObject() for x in archive.portal_catalog(portal_type="Archive",\n
+                                                                         validation_state=\'validated\')]\n
+  previous_archive_list.sort(sort_max_date)\n
+\n
+  if len(previous_archive_list) > 0:\n
+    # Check the date\n
+    for x in len(previous_archive_list):\n
+      previous_archive = previous_archive_list[x]\n
+      # find a previous archive which was not for current catalog\n
+      if previous_archive.getStopDateRangeMax() is not None:\n
+        break\n
+    if previous_archive.getStopDateRangeMax().Date() != min_stop_date:\n
+      msg = Message(domain=\'ui\', message=\'Archive are not contiguous.\')\n
+      raise ValidationFailed, (msg,)\n
+else:\n
+  previous_archive_list = [x.getObject() for x in archive.portal_catalog(portal_type="Archive",\n
+                                                                         validation_state=\'ready\')]\n
+  previous_archive_list.sort(sort_max_date)\n
+\n
+  if len(previous_archive_list) > 0:\n
+    # Check the date\n
+    for x in len(previous_archive_list):\n
+      previous_archive = previous_archive_list[x]\n
+      # find a previous archive which was not for current catalog\n
+      if previous_archive.getStopDateRangeMax() is not None:\n
+        break\n
+    if previous_archive.getStopDateRangeMax().Date() != min_stop_date:\n
+      msg = Message(domain=\'ui\', message=\'Archive are not contiguous.\')\n
       raise ValidationFailed, (msg,)\n
+\n
+\n
+# Check the catalog\n
+previous_archive_list = [x.getObject() for x in archive.portal_catalog(portal_type="Archive",\n
+                                                                       validation_state=[\'validated\', \'ready\'])]\n
+\n
+for arch in previous_archive_list:\n
+  if arch.getCatalogId() == catalog_id and arch is not previous_archive:\n
+    msg = Message(domain=\'ui\', message=\'Use of a former catalog is prohibited.\')\n
+    raise ValidationFailed, (msg,)\n
 
 
 ]]></string> </value>
@@ -157,15 +182,15 @@ if len(previous_archive_list) > 0:\n
                             <string>min_stop_date</string>
                             <string>catalog_id</string>
                             <string>msg</string>
+                            <string>sort_max_date</string>
+                            <string>None</string>
                             <string>append</string>
                             <string>$append0</string>
                             <string>_getiter_</string>
                             <string>x</string>
                             <string>previous_archive_list</string>
-                            <string>sort_max_date</string>
                             <string>len</string>
                             <string>previous_archive</string>
-                            <string>None</string>
                             <string>arch</string>
                           </tuple>
                         </value>
diff --git a/bt5/erp5_archive/bt/change_log b/bt5/erp5_archive/bt/change_log
index e86f897b48..af34b52394 100644
--- a/bt5/erp5_archive/bt/change_log
+++ b/bt5/erp5_archive/bt/change_log
@@ -1,3 +1,6 @@
+2007-11-19 Aurel
+* rewrite workflow script to do more check
+
 2007-11-14 Aurel
 * update workflow to defined h:m:s on archive date, many zsql method and script update to take more cases into account
 
diff --git a/bt5/erp5_archive/bt/revision b/bt5/erp5_archive/bt/revision
index b2412e34df..d1cbcfa540 100644
--- a/bt5/erp5_archive/bt/revision
+++ b/bt5/erp5_archive/bt/revision
@@ -1 +1 @@
-62
\ No newline at end of file
+66
\ No newline at end of file
-- 
2.30.9