Commit f400674c authored by Sebastien Robin's avatar Sebastien Robin

fixed bug in Base_checkCheck, add more checks in Base_checkOrCreateCheck

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14554 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5ab7a62e
...@@ -65,24 +65,13 @@ ...@@ -65,24 +65,13 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>from Products.ERP5Type.Message import Message\n
from Products.ERP5Type.Message import Message\n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
\n \n
# Check that a check exists for given bank account and reference.\n # Check that a check exists for given bank account and reference.\n
result = context.Base_checkOrCreateCheck(reference=reference, \n check = context.Base_checkOrCreateCheck(reference=reference, \n
bank_account=bank_account,\n bank_account=bank_account,\n
resource=resource)\n resource=resource)\n
result_len = len(result)\n
if result_len == 0:\n
msg = Message(domain=\'ui\', message="No such check")\n
raise ValidationFailed, (msg,)\n
elif result_len > 1:\n
msg = Message(domain=\'ui\', message=\'Duplicate checks for the same check number\')\n
raise ValidationFailed, (msg,)\n
\n
check = result[0].getObject()\n
\n \n
bad_simulation_state_dict = {\'draft\': \'The check is not issued yet.\',\n bad_simulation_state_dict = {\'draft\': \'The check is not issued yet.\',\n
\'cancelled\': \'The check has been stopped.\',\n \'cancelled\': \'The check has been stopped.\',\n
...@@ -98,9 +87,7 @@ if simulation_state != \'confirmed\':\n ...@@ -98,9 +87,7 @@ if simulation_state != \'confirmed\':\n
raise ValidationFailed, (msg,)\n raise ValidationFailed, (msg,)\n
\n \n
return check\n return check\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_code</string> </key> <key> <string>_code</string> </key>
...@@ -157,14 +144,11 @@ return check\n ...@@ -157,14 +144,11 @@ return check\n
<string>ValidationFailed</string> <string>ValidationFailed</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>result</string>
<string>len</string>
<string>result_len</string>
<string>msg</string>
<string>_getitem_</string>
<string>check</string> <string>check</string>
<string>bad_simulation_state_dict</string> <string>bad_simulation_state_dict</string>
<string>simulation_state</string> <string>simulation_state</string>
<string>_getitem_</string>
<string>msg</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -121,6 +121,9 @@ check_list = []\n ...@@ -121,6 +121,9 @@ check_list = []\n
bank_account_uid = bank_account.getUid()\n bank_account_uid = bank_account.getUid()\n
resource_value = None\n resource_value = None\n
generic_model = None\n generic_model = None\n
reference_dict = {}\n
# First we must parse everyting to make sure there is no error,\n
# this is safer because we catch Validation in workflow scripts\n
for check_reference in reference_list:\n for check_reference in reference_list:\n
message_tag = \'check_%s_%s_%s\' % (resource, bank_account_uid, check_reference)\n message_tag = \'check_%s_%s_%s\' % (resource, bank_account_uid, check_reference)\n
# just raise an error.\n # just raise an error.\n
...@@ -130,11 +133,26 @@ for check_reference in reference_list:\n ...@@ -130,11 +133,26 @@ for check_reference in reference_list:\n
result = context.portal_catalog(portal_type = \'Check\', reference = check_reference, \n result = context.portal_catalog(portal_type = \'Check\', reference = check_reference, \n
destination_payment_uid = bank_account.getUid(),\n destination_payment_uid = bank_account.getUid(),\n
default_resource_relative_url = resource)\n default_resource_relative_url = resource)\n
if len(result) == 0:\n result_len = len(result)\n
if result_len == 0:\n
if not context.Base_isAutomaticCheckCreationAllowed():\n if not context.Base_isAutomaticCheckCreationAllowed():\n
msg = Message(domain = "ui", message="Sorry, this reference does not exist")\n msg = Message(domain = "ui", message="Sorry, this reference does not exist")\n
raise ValidationFailed, (msg,)\n raise ValidationFailed, (msg,)\n
\n \n
elif result_len >= 1:\n
msg = Message(domain=\'ui\', message=\'Duplicate checks for the same check number\')\n
raise ValidationFailed, (msg,)\n
\n
reference_dict[check_reference] = {}\n
reference_dict[check_reference][\'result\'] = result\n
reference_dict[check_reference][\'result_len\'] = result_len\n
reference_dict[check_reference][\'message_tag\'] = message_tag\n
\n
for check_reference in reference_list:\n
result_len = reference_dict[check_reference][\'result_len\']\n
result = reference_dict[check_reference][\'result\']\n
message_tag = reference_dict[check_reference][\'message_tag\']\n
if result_len == 0:\n
# This happens only if automatic creation is allowed. So create a new check at this point.\n # This happens only if automatic creation is allowed. So create a new check at this point.\n
# Get a checkbook for this bank account.\n # Get a checkbook for this bank account.\n
checkbook = None\n checkbook = None\n
...@@ -260,13 +278,16 @@ return check_list\n ...@@ -260,13 +278,16 @@ return check_list\n
<string>bank_account_uid</string> <string>bank_account_uid</string>
<string>resource_value</string> <string>resource_value</string>
<string>generic_model</string> <string>generic_model</string>
<string>reference_dict</string>
<string>check_reference</string> <string>check_reference</string>
<string>message_tag</string> <string>message_tag</string>
<string>result</string> <string>result</string>
<string>len</string> <string>len</string>
<string>result_len</string>
<string>_write_</string>
<string>_getitem_</string>
<string>checkbook</string> <string>checkbook</string>
<string>composition_related_list</string> <string>composition_related_list</string>
<string>_getitem_</string>
<string>brain</string> <string>brain</string>
<string>obj</string> <string>obj</string>
<string>checkbook_tag</string> <string>checkbook_tag</string>
......
219 223
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment