Commit 6cef7253 authored by Vincent Pelletier's avatar Vincent Pelletier

Make Base_checkOrCreateCheck take a back_account parameter used to override...

Make Base_checkOrCreateCheck take a back_account parameter used to override bank account automatic recovery.
Factorize and cleanup check_deposit_workflow and check_payment_workflow validateConsistency script parts related to check validation.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14532 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9fc242f1
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</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 encoding="cdata"><![CDATA[
# Check that a check exists for given bank account and reference.\n
result = context.Base_checkOrCreateCheck(reference=reference, bank_account=bank_account)\n
resul_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
bad_simulation_state_dict = {\'draft\': \'The check is not issued yet.\',\n
\'cancelled\': \'The check has been stopped.\',\n
\'delivered\': \'The check has already been cashed.\',\n
\'stopped\': \'The check is stopped.\'}\n
\n
simulation_state = check.getSimulationState()\n
if simulation_state != \'confirmed\':\n
if simulation_state in bad_simulation_state_dict:\n
msg = Message(domain=\'ui\', message=bad_simulation_state_dict[simulation_state])\n
else:\n
msg = \'Invalid and unhandled simulation state: %s\' % (simulation_state, )\n
raise ValidationFailed, (msg,)\n
\n
return check\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>bank_account, reference</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>2</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>bank_account</string>
<string>reference</string>
<string>_getattr_</string>
<string>context</string>
<string>result</string>
<string>len</string>
<string>resul_len</string>
<string>result_len</string>
<string>Message</string>
<string>msg</string>
<string>ValidationFailed</string>
<string>_getitem_</string>
<string>check</string>
<string>bad_simulation_state_dict</string>
<string>simulation_state</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>Base_checkCheck</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -74,12 +74,11 @@ ...@@ -74,12 +74,11 @@
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
if destination:\n if bank_account is None:\n
if destination:\n
bank_account = context.getDestinationPaymentValue()\n bank_account = context.getDestinationPaymentValue()\n
elif source:\n elif source:\n
bank_account = context.getSourcePaymentValue()\n bank_account = context.getSourcePaymentValue()\n
else:\n
bank_account = None\n
\n \n
if bank_account is None:\n if bank_account is None:\n
msg = Message(domain=\'ui\',message=\'Sorry, you must select an account\')\n msg = Message(domain=\'ui\',message=\'Sorry, you must select an account\')\n
...@@ -119,7 +118,7 @@ for check_reference in reference_list:\n ...@@ -119,7 +118,7 @@ for check_reference in reference_list:\n
if context.portal_activities.countMessageWithTag(message_tag) != 0:\n if context.portal_activities.countMessageWithTag(message_tag) != 0:\n
msg = Message(domain=\'ui\', message="This check number is already being indexed.")\n msg = Message(domain=\'ui\', message="This check number is already being indexed.")\n
raise ValidationFailed, (msg,)\n raise ValidationFailed, (msg,)\n
result = context.portal_catalog(portal_type = \'Check\', reference = check_reference)\n result = context.portal_catalog(portal_type = \'Check\', reference = check_reference, destination_payment_uid = bank_account.getUid())\n
if len(result) == 0:\n if len(result) == 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
...@@ -180,7 +179,7 @@ return check_list\n ...@@ -180,7 +179,7 @@ return check_list\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>reference=None, reference_range_min=None, reference_range_max=None, source=0, destination=1</string> </value> <value> <string>reference=None, reference_range_min=None, reference_range_max=None, source=0, destination=1, bank_account=None</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -200,7 +199,7 @@ return check_list\n ...@@ -200,7 +199,7 @@ return check_list\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>5</int> </value> <value> <int>6</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
...@@ -211,14 +210,14 @@ return check_list\n ...@@ -211,14 +210,14 @@ return check_list\n
<string>reference_range_max</string> <string>reference_range_max</string>
<string>source</string> <string>source</string>
<string>destination</string> <string>destination</string>
<string>bank_account</string>
<string>Products.ERP5Type.Message</string> <string>Products.ERP5Type.Message</string>
<string>Message</string> <string>Message</string>
<string>Products.DCWorkflow.DCWorkflow</string> <string>Products.DCWorkflow.DCWorkflow</string>
<string>ValidationFailed</string> <string>ValidationFailed</string>
<string>None</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>bank_account</string>
<string>None</string>
<string>msg</string> <string>msg</string>
<string>reference_list</string> <string>reference_list</string>
<string>int</string> <string>int</string>
...@@ -254,6 +253,7 @@ return check_list\n ...@@ -254,6 +253,7 @@ return check_list\n
<none/> <none/>
<int>0</int> <int>0</int>
<int>1</int> <int>1</int>
<none/>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -116,36 +116,7 @@ for check_operation_line in transaction.contentValues(filter = {\'portal_type\' ...@@ -116,36 +116,7 @@ for check_operation_line in transaction.contentValues(filter = {\'portal_type\'
msg = Message(domain=\'ui\', message="Unknown error code.")\n msg = Message(domain=\'ui\', message="Unknown error code.")\n
raise ValidationFailed, (msg,)\n raise ValidationFailed, (msg,)\n
\n \n
result = context.portal_catalog(portal_type = \'Check\', reference = check_number)\n transaction.Base_checkCheck(bank_account=source_bank_account, reference=check_number)\n
if len(result) == 0:\n
# Until a certain date, ERP5 allows the user to generate a check automatically.\n
from DateTime import DateTime\n
now = DateTime()\n
stop_date = context.Baobab_getAutomaticCheckCreationStopDate()\n
if now > stop_date:\n
msg = Message(domain=\'ui\', message=\'No such check.\')\n
raise ValidationFailed, (msg,)\n
elif len(result) == 1:\n
# Check if this check has the same bank account as the payment.\n
check = result[0].getObject()\n
if check_operation_line.getSourcePaymentReference() != check.getDestinationPaymentReference():\n
msg = Message(domain=\'ui\', message=\'Bank account do not match between payment and check.\')\n
raise ValidationFailed, (msg,)\n
# Check the state of this check.\n
state = check.getSimulationState()\n
if state != \'confirmed\':\n
if state == \'draft\':\n
msg = Message(domain=\'ui\', message=\'The check is not issued yet.\')\n
elif state == \'cancelled\':\n
msg = Message(domain=\'ui\', message=\'The check has been canceled.\')\n
elif state == \'delivered\':\n
msg = Message(domain=\'ui\', message=\'The check has already been cashed.\')\n
elif state == \'stopped\':\n
msg = Message(domain=\'ui\', message=\'The check has been stopped.\')\n
raise ValidationFailed, (msg,)\n
else:\n
msg = Message(domain=\'ui\', message="Duplicated checks for the same check number.")\n
raise ValidationFailed, (msg,)\n
\n \n
if transaction.getSimulationState() == "draft":\n if transaction.getSimulationState() == "draft":\n
context.updateBankingOperation(state_change)\n context.updateBankingOperation(state_change)\n
...@@ -225,13 +196,6 @@ if transaction.getSimulationState() == "draft":\n ...@@ -225,13 +196,6 @@ if transaction.getSimulationState() == "draft":\n
<string>source_bank_account</string> <string>source_bank_account</string>
<string>context</string> <string>context</string>
<string>error</string> <string>error</string>
<string>result</string>
<string>len</string>
<string>DateTime</string>
<string>now</string>
<string>stop_date</string>
<string>check</string>
<string>state</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -124,37 +124,7 @@ check_number = transaction.getAggregateFreeText()\n ...@@ -124,37 +124,7 @@ check_number = transaction.getAggregateFreeText()\n
if not check_number:\n if not check_number:\n
msg = Message(domain=\'ui\', message="Check not defined.")\n msg = Message(domain=\'ui\', message="Check not defined.")\n
raise ValidationFailed, (msg,)\n raise ValidationFailed, (msg,)\n
\n transaction.Base_checkCheck(reference=check_number, bank_account=bank_account)\n
result = context.portal_catalog(portal_type = \'Check\', title = check_number,simulation_state=\'confirmed\')\n
if len(result) == 0:\n
# Until a certain date, ERP5 allows the user to generate a check automatically.\n
from DateTime import DateTime\n
now = DateTime()\n
stop_date = context.Baobab_getAutomaticCheckCreationStopDate()\n
if now > stop_date:\n
msg = Message(domain=\'ui\', message="No such check")\n
raise ValidationFailed, (msg,)\n
elif len(result) == 1:\n
# Check if this check has the same bank account as the payment.\n
check = result[0].getObject()\n
if transaction.getDestinationPaymentReference() != check.getDestinationPaymentReference():\n
msg = Message(domain=\'ui\', message="Bank account do not match between payment and check.")\n
raise ValidationFailed, (msg,)\n
# Check the state of this check.\n
state = check.getSimulationState()\n
if state != \'confirmed\':\n
if state == \'draft\':\n
msg = Message(domain=\'ui\', message=\'The check is not issued yet.\')\n
elif state == \'cancelled\':\n
msg = Message(domain=\'ui\', message=\'The check has been stopped.\')\n
elif state == \'delivered\':\n
msg = Message(domain=\'ui\', message=\'The check has already been cashed.\')\n
elif state == \'stopped\':\n
msg = Message(domain=\'ui\', message=\'The check is stopped.\')\n
raise ValidationFailed, (msg,)\n
else:\n
msg = Message(domain=\'ui\', message=\'Duplicate checks for the same check number\')\n
raise ValidationFailed, (msg,)\n
\n \n
context.updateBankingOperation(state_change)\n context.updateBankingOperation(state_change)\n
...@@ -237,11 +207,6 @@ context.updateBankingOperation(state_change)\n ...@@ -237,11 +207,6 @@ context.updateBankingOperation(state_change)\n
<string>bank_account</string> <string>bank_account</string>
<string>check_number</string> <string>check_number</string>
<string>context</string> <string>context</string>
<string>result</string>
<string>now</string>
<string>stop_date</string>
<string>check</string>
<string>state</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
199 201
\ 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