From a6ceb0bfc6bb8f4497a75872e29051089b6060d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Mon, 15 Jun 2009 08:21:15 +0000
Subject: [PATCH] when checking ofr the number of account or the existence of
 the same reference, do not take into account the current bank account on
 which the check is performed

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27551 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../scripts/checkBankAccount.xml                | 17 +++++++++++------
 bt5/erp5_banking_core/bt/revision               |  2 +-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/bt5/erp5_banking_core/WorkflowTemplateItem/portal_workflow/bank_account_workflow/scripts/checkBankAccount.xml b/bt5/erp5_banking_core/WorkflowTemplateItem/portal_workflow/bank_account_workflow/scripts/checkBankAccount.xml
index 9e99670b26..7fee01964e 100644
--- a/bt5/erp5_banking_core/WorkflowTemplateItem/portal_workflow/bank_account_workflow/scripts/checkBankAccount.xml
+++ b/bt5/erp5_banking_core/WorkflowTemplateItem/portal_workflow/bank_account_workflow/scripts/checkBankAccount.xml
@@ -80,7 +80,7 @@ if bank_account.getParentValue().getPortalType()== \'Person\':\n
   # Can\'t have two bank account\n
   for obj in bank_account.getParentValue().objectValues():\n
     if obj.getPortalType() == "Bank Account" and obj.getValidationState() not in (\'draft\', \'closed\') \\\n
-           and obj.getSource() == bank_account.getSource():\n
+           and obj.getSource() == bank_account.getSource() and obj.getPath()!= bank_account.getPath():\n
       raise ValidationFailed, "You cannot open two bank accounts for the same person on the same site"\n
 \n
 valid_state = ["valid", "being_closed", "validating_closing",\n
@@ -90,18 +90,22 @@ valid_state = ["valid", "being_closed", "validating_closing",\n
 same_ref_list = context.portal_catalog(validation_state=valid_state,\n
                                        portal_type="Bank Account",\n
                                        reference=bank_account.getReference())\n
+for doc in same_ref_list:\n
+  if doc.getPath() != bank_account.getPath():\n
+    context.log("doc path %s" %(doc.getPath(),))\n
+    raise ValidationFailed, "Bank account with same reference already exists"\n
 \n
-if len(same_ref_list):\n
-  raise ValidationFailed, "Bank account with same reference already exists"\n
 \n
 # Same for internal reference if exists\n
 if bank_account.getInternalBankAccountNumber() not in ("", None):\n
   same_ref_list = context.portal_catalog(validation_state=valid_state,\n
                                          portal_type="Bank Account",\n
                                          string_index=bank_account.getInternalBankAccountNumber())\n
-  \n
-  if len(same_ref_list):\n
-    raise ValidationFailed, "Bank account with same internal reference already exists"\n
+\n
+  for doc in same_ref_list:\n
+    if doc.getPath() != bank_account.getPath():\n
+      context.log("doc path %s" %(doc.getPath(),))\n
+      raise ValidationFailed, "Bank account with same internal reference already exists"\n
 </string> </value>
         </item>
         <item>
@@ -160,6 +164,7 @@ if bank_account.getInternalBankAccountNumber() not in ("", None):\n
                             <string>valid_state</string>
                             <string>context</string>
                             <string>same_ref_list</string>
+                            <string>doc</string>
                             <string>None</string>
                           </tuple>
                         </value>
diff --git a/bt5/erp5_banking_core/bt/revision b/bt5/erp5_banking_core/bt/revision
index 6efca19ea0..9301519f58 100644
--- a/bt5/erp5_banking_core/bt/revision
+++ b/bt5/erp5_banking_core/bt/revision
@@ -1 +1 @@
-481
\ No newline at end of file
+483
\ No newline at end of file
-- 
2.30.9