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

- CheckbookReception_generateIemList reviewed by Vincent

- We now generate checks when we receive checkbooks
- some allowed content types where missing for traveler check sale

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13587 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8f9cfdf3
......@@ -49,6 +49,7 @@
<item>Traveler Check Purchase</item>
</portal_type>
<portal_type id="Traveler Check Sale">
<item>Banking Operation Line</item>
<item>Checkbook Delivery Line</item>
</portal_type>
<portal_type id="Traveler Check Sale Module">
......
......@@ -68,7 +68,12 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># We will need to create all checks for all checkbooks\n
<value> <string encoding="cdata"><![CDATA[
# XXX: this script is not used any more, since checks are already\n
# generated when checks & checkbooks are received.\n
\n
# We will need to create all checks for all checkbooks\n
# Then all of them should be set as confirmed\n
transaction = state_change[\'object\']\n
\n
......@@ -88,7 +93,9 @@ for line in line_list:\n
elif aggregate.getPortalType()==\'Check\':\n
aggregate.setStartDate(transaction.getStartDate())\n
aggregate.confirm()\n
</string> </value>
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
......
......@@ -38,7 +38,7 @@
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string>updateCheckAndCheckbook</string> </value>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
......
......@@ -73,69 +73,162 @@
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
transaction = state_change.object\n
\n
def getReference(reference):\n
"""\n
Convert a reference into an int.\n
"""\n
# First convert to float to avoid failing to convert if reference = \'1.0\'\n
return int(float(reference))\n
\n
def generateReference(reference, ignored):\n
"""\n
Convert an int into a reference\n
"""\n
return str(reference)\n
\n
def validateTravelerCheckReferenceFormat(traveler_check_reference):\n
"""\n
Check provided traveler_check_reference format\n
"""\n
if len(traveler_check_reference) != 10:\n
raise ValueError, \'Traveler check reference must be 10-char long.\'\n
int(traveler_check_reference[4:])\n
\n
def getTravelerCheckReferenceNumber(traveler_check_reference):\n
"""\n
Extract traveler check reference number\n
"""\n
validateTravelerCheckReferenceFormat(traveler_check_reference)\n
return int(traveler_check_reference[4:])\n
\n
def getTravelerCheckReferencePrefix(traveler_check_reference):\n
"""\n
Extract traveler check reference prefix\n
"""\n
validateTravelerCheckReferenceFormat(traveler_check_reference)\n
return traveler_check_reference[:4]\n
\n
def generateTravelerCheckReference(number, original_traveler_check_reference):\n
"""\n
Generate a traveler check reference from an existing reference (to\n
extract its prefix) and a new numerical value.\n
"""\n
if not same_type(number, 0):\n
raise ValueError, \'Traveler check number must be only numeric.\'\n
if len(str(number)) > 6:\n
raise ValueError, \'Traveler check number representation length must not exceed 6 char.\'\n
prefix = getTravelerCheckReferencePrefix(original_traveler_check_reference)\n
return \'%s%06d\' % (prefix, number)\n
\n
def assertReferenceMatchListEmpty(match_list):\n
"""\n
Check that the list is empty, otherwise gather all conflicting references and display them in the error message.\n
TODO: make the error message Localizer-friendly\n
"""\n
if len(match_list) > 0:\n
matched_reference_list = []\n
for match in match_list:\n
matched_reference_list.append(match.getReference())\n
raise ValidationError, \'The following references are already allocated : %s\' % (matched_reference_list, )\n
\n
portal_activities = conetxt.getPortalObject().portal_activities\n
def checkReferenceUniqueness(reference, model):\n
"""\n
Check the given reference not to already exist.\n
"""\n
match_list = portal.portal_catalog(portal_type=\'Check\', reference=reference)\n
assertReferenceMatchListEmpty(match_list)\n
if portal_activities.countMessageWithTag(\'check_%s_%s\' % (model, reference)) != 0:\n
raise ValidationError, \'This reference is alredy scheduled for indexing, and so is already allocated : %s\' % (reference, )\n
\n
# Check getBaobabSource and getBaobabDestination\n
transaction.Base_checkBaobabSourceAndDestination()\n
\n
\n
delivery = state_change.object\n
portal = context.getPortalObject()\n
\n
# We must parse all lines of checkbook reception and then\n
# generate all items. We do not need to check data\n
# because everything is already checked in the fast input\n
line_portal_type = delivery.getPortalType() + \' Line\'\n
line_list = delivery.objectValues(portal_type=line_portal_type)\n
line_list = delivery.objectValues(portal_type=delivery.getPortalType() + \' Line\')\n
\n
for line in line_list:\n
quantity = line.getQuantity()\n
resource = line.getResourceValue()\n
reference_range_min = line.getReferenceRangeMin()\n
reference_range_max = line.getReferenceRangeMax()\n
quantity = line.getQuantity()\n
resource = line.getResourceValue()\n
reference_range_min = line.getReferenceRangeMin()\n
\n
# We will look where we should create as many items\n
# as necessary and construct by the same time\n
# the aggregate list that we will store on the line\n
resource_portal_type = resource.getPortalType()\n
if resource_portal_type == \'Checkbook Model\':\n
is_checkbook = True\n
module = portal.checkbook_module\n
model = resource.getTitle().replace(\'Ch\xc3\xa9quier\', \'Ch\xc3\xa8que\') # XXX: Yuck yuck.\n
# XXX: portal_type value is hardcoded because I don\'t want to get the\n
# portaltype on each created object as it will always be the same.\n
# We need a method to get the default content portaltype on a Folder.\n
check_amount = line.getCheckAmount()\n
check_quantity = int(portal.restrictedTraverse(check_amount).getQuantity())\n
reference_to_int = getReference\n
int_to_reference = generateReference\n
else:\n
is_checkbook = False\n
module = portal.check_module\n
model = resource.getTitle()\n
# XXX: portal_type value is hardcoded, see XXX above.\n
if resource_portal_type == \'Check Model\' and resource.isFixedPrice():\n
reference_to_int = getTravelerCheckReferenceNumber\n
int_to_reference = generateTravelerCheckReference\n
else:\n
reference_to_int = getReference\n
int_to_reference = generateReference\n
\n
aggregate_list = []\n
for i in xrange(quantity):\n
item = module.newContent()\n
item.setDestinationPayment(line.getDestinationPayment())\n
item.setDestinationTrade(line.getDestinationTrade())\n
item.setResourceValue(resource)\n
if is_checkbook:\n
item.setReferenceRangeMin(reference_range_min)\n
last_reference_value = reference_to_int(reference_range_min) + check_quantity - 1\n
reference_range_max = int_to_reference(last_reference_value, reference_range_min)\n
item.setReferenceRangeMax(reference_range_max)\n
item.setTitle(\'%s - %s\' % (reference_range_min, reference_range_max))\n
item.setCheckAmount(check_amount)\n
\n
start_date = transaction.getStartDate()\n
destination_section = item.getDestinationSection()\n
item.setStartDate(start_date)\n
for j in xrange(reference_to_int(reference_range_min), last_reference_value + 1):\n
reference = int_to_reference(j, reference_range_min)\n
checkReferenceUniqueness(reference, model)\n
check = item.newContent(portal_type=\'Check\', title=str(reference), activate_kw={\'tag\': \'check_%s_%s\' % (model, reference)})\n
check.setDestination(destination_section)\n
check.setStartDate(start_date)\n
check.setReference(reference)\n
check.confirm()\n
\n
# We will look where we should create as many items\n
# as necessary and construct by the same time\n
# the aggregate list that we will store on the line\n
checkbook = 0\n
if resource.getPortalType()==\'Checkbook Model\':\n
checkbook = 1\n
module = portal.checkbook_module\n
else:\n
module = portal.check_module\n
if checkbook:\n
check_amount_value = portal.restrictedTraverse(check_amount)\n
check_quantity = check_amount_value.getQuantity()\n
\n
aggregate_list = []\n
for i in xrange(0,quantity):\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)-1)\n
item.setReferenceRangeMax(reference_range_max)\n
item.setTitle(\'%s - %s\' % (reference_range_min, reference_range_max))\n
reference_range_min = str(int(reference_range_max) + 1)\n
item.setCheckAmount(check_amount)\n
else:\n
item.setReference(reference_range_min)\n
item.setTitle(reference_range_min)\n
if quantity>1:\n
reference_range_min = str(int(float(reference_range_min)) + 1)\n
if len(resource.objectValues())>0:\n
item_type = line.getCheckTypeValue()\n
item.setPrice(item_type.getPrice())\n
item.setPriceCurrency(line.getPriceCurrency())\n
item.setDestinationPayment(line.getDestinationPayment())\n
item.setDestinationTrade(line.getDestinationTrade())\n
item.setResourceValue(resource)\n
# I (seb) think this is a big mistake\n
#if item.getPortalType()==\'Check\':\n
# portal.portal_workflow.doActionFor(item,\'confirm_action\',\n
# wf_id=\'check_workflow\')\n
aggregate_list.append(item)\n
\n
# Finally set the aggregate list on the line\n
line.setAggregateValueList(aggregate_list)\n
checkReferenceUniqueness(reference_range_min, model)\n
item.setReference(reference_range_min)\n
item.setTitle(reference_range_min)\n
if len(resource.objectValues()) > 0:\n
item_type = line.getCheckTypeValue()\n
item.setPrice(item_type.getPrice())\n
item.setPriceCurrency(line.getPriceCurrency())\n
last_reference_value = reference_to_int(reference_range_min)\n
# update reference_range_min for the next pass\n
reference_range_min = int_to_reference(last_reference_value + 1, reference_range_min)\n
# I (seb) think this is a big mistake\n
#if item.getPortalType()==\'Check\':\n
# portal.portal_workflow.doActionFor(item,\'confirm_action\',\n
# wf_id=\'check_workflow\')\n
aggregate_list.append(item)\n
\n
# Finally set the aggregate list on the line\n
line.setAggregateValueList(aggregate_list)\n
]]></string> </value>
......@@ -191,29 +284,48 @@ for line in line_list:\n
<string>ValidationFailed</string>
<string>_getattr_</string>
<string>transaction</string>
<string>getReference</string>
<string>generateReference</string>
<string>validateTravelerCheckReferenceFormat</string>
<string>getTravelerCheckReferenceNumber</string>
<string>getTravelerCheckReferencePrefix</string>
<string>generateTravelerCheckReference</string>
<string>assertReferenceMatchListEmpty</string>
<string>conetxt</string>
<string>portal_activities</string>
<string>portal</string>
<string>checkReferenceUniqueness</string>
<string>delivery</string>
<string>context</string>
<string>portal</string>
<string>line_portal_type</string>
<string>line_list</string>
<string>_getiter_</string>
<string>line</string>
<string>quantity</string>
<string>resource</string>
<string>reference_range_min</string>
<string>reference_range_max</string>
<string>check_amount</string>
<string>checkbook</string>
<string>resource_portal_type</string>
<string>True</string>
<string>is_checkbook</string>
<string>module</string>
<string>check_amount_value</string>
<string>model</string>
<string>check_amount</string>
<string>int</string>
<string>check_quantity</string>
<string>reference_to_int</string>
<string>int_to_reference</string>
<string>False</string>
<string>aggregate_list</string>
<string>xrange</string>
<string>i</string>
<string>item</string>
<string>last_reference_value</string>
<string>reference_range_max</string>
<string>start_date</string>
<string>destination_section</string>
<string>j</string>
<string>reference</string>
<string>str</string>
<string>int</string>
<string>float</string>
<string>check</string>
<string>len</string>
<string>item_type</string>
</tuple>
......
......@@ -30,6 +30,16 @@
<none/>
</value>
</item>
<item>
<key> <string>creation_guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
......@@ -44,6 +54,10 @@
<key> <string>initial_state</string> </key>
<value> <string>draft</string> </value>
</item>
<item>
<key> <string>manager_bypass</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
......@@ -60,7 +74,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Checkbook Delivery Workflow</string> </value>
<value> <string>Traveler Check Purchase Workflow</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -30,6 +30,16 @@
<none/>
</value>
</item>
<item>
<key> <string>creation_guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
......@@ -44,6 +54,10 @@
<key> <string>initial_state</string> </key>
<value> <string>draft</string> </value>
</item>
<item>
<key> <string>manager_bypass</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
......@@ -60,7 +74,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Checkbook Delivery Workflow</string> </value>
<value> <string>Traveler Check Sale Workflow</string> </value>
</item>
</dictionary>
</pickle>
......
118
\ No newline at end of file
120
\ No newline at end of file
......@@ -16,4 +16,5 @@ Stop Payment | Checkbook Delivery Line
Traveler Check Purchase Module | Traveler Check Purchase
Traveler Check Purchase | Checkbook Delivery Line
Traveler Check Sale Module | Traveler Check Sale
Traveler Check Sale | Banking Operation Line
Traveler Check Sale | Checkbook Delivery Line
\ 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