Commit 1b8ea4f6 authored by Sebastien Robin's avatar Sebastien Robin

create the right number of check inside the checkbook + small fixes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9595 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7f2d930a
......@@ -341,6 +341,14 @@
<string>reference_range_max</string>
<string>Stop Number</string>
</tuple>
<tuple>
<string>check_amount_title</string>
<string>Number of checks</string>
</tuple>
<tuple>
<string>check_type_title</string>
<string>Value of check</string>
</tuple>
<tuple>
<string>destination_section</string>
<string>Owner</string>
......
......@@ -74,6 +74,12 @@
transaction = state_change[\'object\']\n
bank_account = transaction.getDestinationPaymentValue()\n
check_number = transaction.getAggregateFreeText()\n
message_tag = \'check_%s\' % (check_number, )\n
\n
# XXX: no need to handle this cleanly for now, so just raise an error.\n
if context.portal_activities.countMessageWithTag(message_tag) != 0:\n
msg = Message(domain=\'ui\', message="This check number is already being indexed.")\n
raise ValidationFailed, (msg,)\n
\n
result = context.portal_catalog(portal_type = \'Check\', reference = check_number)\n
if len(result) == 0:\n
......@@ -81,7 +87,7 @@ if len(result) == 0:\n
\n
# Get a checkbook for this bank account.\n
checkbook = None\n
generic_model = context.portal_catalog(portal_type = \'Checkbook Model\', id = \'generic_checkbook\')[0].getObject()\n
generic_model = context.portal_catalog(portal_type = \'Checkbook Model\', title = \'Generic\')[0].getObject()\n
# XXX it would be better to use a related key for this, but z_related_resource is too specific to\n
# movement at the moment.\n
for brain in context.portal_catalog(portal_type = \'Checkbook\',\n
......@@ -99,9 +105,7 @@ if len(result) == 0:\n
destination_payment_value = bank_account,\n
immediate_reindex = 1)\n
# Create a check.\n
# To prevent duplicated checks for a single check number, index this new check immediately.\n
# This has a performance penalty, but this part of the script will rarely be called (once per check number).\n
check = checkbook.newContent(portal_type = \'Check\', reference = check_number, immediate_reindex = 1)\n
check = checkbook.newContent(portal_type = \'Check\', reference = check_number, activate_kw={\'tag\': message_tag})\n
# Automatically issue this check.\n
check.confirm()\n
else:\n
......@@ -179,7 +183,11 @@ transaction.edit(aggregate = check.getRelativeUrl())\n
<string>_getattr_</string>
<string>bank_account</string>
<string>check_number</string>
<string>message_tag</string>
<string>context</string>
<string>Message</string>
<string>msg</string>
<string>ValidationFailed</string>
<string>result</string>
<string>len</string>
<string>None</string>
......
......@@ -94,15 +94,21 @@ context.validateConsistency(state_change)\n
\n
line = transaction.movement\n
bank_account = transaction.getDestinationPaymentValue()\n
price = transaction.getSourceTotalAssetPrice() \n
price = transaction.getSourceTotalAssetPrice()\n
\n
# immediate reindex is required to make this operation atomic.\n
line.immediateReindexObject()\n
# this prevents multiple transactions from being committed at the same time for this bank account.\n
bank_account.serialize()\n
\n
# Check if the banking operation is correct.\n
if - price != transaction.getTotalPrice(portal_type = \'Banking Operation Line\'):\n
# Make sure there are no other operations pending for this account\n
if context.BankAccount_isMessagePending(bank_account):\n
msg = Message(domain=\'ui\', message="There are operations pending for this account that prevent form calculating its position. Please try again later.")\n
raise ValidationFailed, (msg,)\n
\n
# Index the banking operation line so it impacts account position\n
context.BankingOperationLine_index(line)\n
\n
# Check if the banking operation is correct. Do not depend on catalog because line might not be indexed immediatelly.\n
if - price != (line.getPrice() * line.getQuantity()):\n
msg = Message(domain=\'ui\', message=\'Banking operation and check payment price do not match.\')\n
raise ValidationFailed, (msg,)\n
\n
......
......@@ -104,7 +104,7 @@ for line in line_list:\n
item = module.newContent()\n
if checkbook:\n
item.setReferenceRangeMin(reference_range_min)\n
reference_range_max = str(int(float(reference_range_min)) + int(check_quantity))\n
reference_range_max = str(int(float(reference_range_min)) + int(check_quantity)-1)\n
item.setReferenceRangeMax(reference_range_max)\n
item.setTitle(\'%s - %s\' % (reference_range_min, reference_range_max))\n
reference_range_min = reference_range_max\n
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.DCWorkflow.Worklists</string>
<string>WorklistDefinition</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>global</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string>Drafts to Validate (%(count)s)</string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string encoding="cdata"><![CDATA[
Base_viewWorklist?simulation_state=draft&reset=1&portal_type=Checkbook Reception
]]></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Drafts to Validate</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>draft</string> </value>
</item>
<item>
<key> <string>var_matches</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Products.DCWorkflow.Guard</string>
<string>Guard</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>roles</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<tuple>
<string>Persistence</string>
<string>PersistentMapping</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_container</string> </key>
<value>
<dictionary>
<item>
<key> <string>portal_type</string> </key>
<value>
<tuple>
<string>Checkbook Reception</string>
</tuple>
</value>
</item>
<item>
<key> <string>simulation_state</string> </key>
<value>
<tuple>
<string>draft</string>
</tuple>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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