Commit c33aad05 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Avoid load three times the bank account from the ZODB.

- Pass destination payment value instead of reloading it.
- Factorise catalog keyword arguments.
- Remove some commented out lines.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41946 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9c7a4723
...@@ -115,45 +115,47 @@ def generateTravelerCheckReference(number, original_traveler_check_reference):\n ...@@ -115,45 +115,47 @@ def generateTravelerCheckReference(number, original_traveler_check_reference):\n
prefix = getTravelerCheckReferencePrefix(original_traveler_check_reference)\n prefix = getTravelerCheckReferencePrefix(original_traveler_check_reference)\n
return \'%s%06d\' % (prefix, number)\n return \'%s%06d\' % (prefix, number)\n
\n \n
def assertReferenceMatchListEmpty(match_list, destination_payment_uid):\n def assertReferenceMatchListEmpty(match_list, internal_bank_account_number):\n
"""\n """\n
Check that the list is empty, otherwise gather all conflicting references and display them in the error message.\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 TODO: make the error message Localizer-friendly\n
"""\n """\n
if len(match_list) > 0:\n if len(match_list) > 0:\n
account = context.portal_catalog(uid=destination_payment_uid)[0].getObject()\n
matched_reference_list = []\n matched_reference_list = []\n
for match in match_list:\n for match in match_list:\n
matched_reference_list.append(\'%s (%s)\' % (match.getReference(), account.getInternalBankAccountNumber()))\n matched_reference_list.append(\'%s (%s)\' % (match.getReference(), internal_bank_account_number))\n
message = Message(domain=\'ui\', message=\'The following references are already allocated : $reference_list\',\n message = Message(domain=\'ui\', message=\'The following references are already allocated : $reference_list\',\n
mapping={\'reference_list\': matched_reference_list})\n mapping={\'reference_list\': matched_reference_list})\n
raise ValidationFailed, (message,)\n raise ValidationFailed, (message,)\n
\n \n
def checkReferenceListUniqueness(reference_list, model_uid, destination_payment_uid, unique_per_account):\n def checkReferenceListUniqueness(reference_list, model_uid, destination_payment_value, unique_per_account):\n
"""\n """\n
Check each given reference not to already exist.\n Check each given reference not to already exist.\n
"""\n """\n
if destination_payment_uid is None or not unique_per_account:\n catalog_kw = dict(\n
match_list = portal.portal_catalog(portal_type=\'Check\', reference=reference_list, default_resource_uid=model_uid, simulation_state=\'!=deleted\')\n portal_type=\'Check\',\n
reference=reference_list,\n
simulation_state=\'!=deleted\',\n
default_resource_uid=model_uid,\n
)\n
if destination_payment_value is None:\n
destination_payment_uid = None\n
internal_bank_account_number = None\n
else:\n else:\n
match_list = portal.portal_catalog(portal_type=\'Check\', reference=reference_list, destination_payment_uid=destination_payment_uid, default_resource_uid=model_uid,\n destination_payment_uid = destination_payment_value.getUid()\n
simulation_state=\'!=deleted\')\n internal_bank_account_number = destination_payment_value.getInternalBankAccountNumber()\n
assertReferenceMatchListEmpty(match_list, destination_payment_uid)\n if unique_per_account:\n
catalog_kw[\'destination_payment_uid\'] = destination_payment_uid\n
match_list = portal.portal_catalog(**catalog_kw)\n
assertReferenceMatchListEmpty(match_list, internal_bank_account_number)\n
for reference in reference_list:\n for reference in reference_list:\n
tag = \'check_%s_%s_%s\' % (model_uid, destination_payment_uid, reference)\n tag = \'check_%s_%s_%s\' % (model_uid, destination_payment_uid, reference)\n
if encountered_check_identifiers_dict.has_key(tag):\n if encountered_check_identifiers_dict.has_key(tag):\n
account = context.portal_catalog(uid=destination_payment_uid)[0].getObject()\n
message = Message(domain=\'ui\', message=\'The following references are already allocated : $reference_list\',\n message = Message(domain=\'ui\', message=\'The following references are already allocated : $reference_list\',\n
mapping={\'reference_list\': [\'%s (%s)\' % (reference, account.getInternalBankAccountNumber()) ]})\n mapping={\'reference_list\': [\'%s (%s)\' % (reference, internal_bank_account_number) ]})\n
raise ValidationFailed, (message,)\n raise ValidationFailed, (message,)\n
encountered_check_identifiers_dict[tag] = None\n encountered_check_identifiers_dict[tag] = None\n
\n \n
def checkReferenceUniqueness(reference, model_uid, destination_payment_uid, unique_per_account):\n
"""\n
Check the given reference not to already exist.\n
"""\n
checkReferenceListUniqueness([reference, ], model_uid, destination_payment_uid, unique_per_account=unique_per_account)\n
\n
start_date = checkbook_reception.getStartDate()\n start_date = checkbook_reception.getStartDate()\n
destination = checkbook_reception.getDestination()\n destination = checkbook_reception.getDestination()\n
\n \n
...@@ -200,11 +202,9 @@ if resource.getAccountNumberEnabled():\n ...@@ -200,11 +202,9 @@ if resource.getAccountNumberEnabled():\n
if destination_payment_value is None:\n if destination_payment_value is None:\n
message = Message(domain=\'ui\', message=\'There is not destination payment on line with id: $id\', mapping={\'id\': context.getId()})\n message = Message(domain=\'ui\', message=\'There is not destination payment on line with id: $id\', mapping={\'id\': context.getId()})\n
raise ValueError, (message,)\n raise ValueError, (message,)\n
destination_payment_uid = destination_payment_value.getUid()\n
destination_trade = line.getDestinationTrade()\n destination_trade = line.getDestinationTrade()\n
else:\n else:\n
destination_payment_value = None\n destination_payment_value = None\n
destination_payment_uid = None\n
\n \n
unique_per_account = resource.isUniquePerAccount()\n unique_per_account = resource.isUniquePerAccount()\n
aggregate_list = []\n aggregate_list = []\n
...@@ -221,7 +221,7 @@ for i in xrange(quantity):\n ...@@ -221,7 +221,7 @@ for i in xrange(quantity):\n
reference_list = [int_to_reference(x, reference_range_min) for x in range(reference_to_int(reference_range_min), last_reference_value + 1)]\n reference_list = [int_to_reference(x, reference_range_min) for x in range(reference_to_int(reference_range_min), last_reference_value + 1)]\n
reference_range_max = int_to_reference(last_reference_value, reference_range_min)\n reference_range_max = int_to_reference(last_reference_value, reference_range_min)\n
if check == 1:\n if check == 1:\n
checkReferenceListUniqueness(reference_list, model_uid, destination_payment_uid, unique_per_account)\n checkReferenceListUniqueness(reference_list, model_uid, destination_payment_value, unique_per_account)\n
if create == 1:\n if create == 1:\n
item.setReferenceRangeMax(reference_range_max)\n item.setReferenceRangeMax(reference_range_max)\n
item.setReferenceRangeMin(reference_range_min)\n item.setReferenceRangeMin(reference_range_min)\n
...@@ -233,7 +233,6 @@ for i in xrange(quantity):\n ...@@ -233,7 +233,6 @@ for i in xrange(quantity):\n
if confirm_check:\n if confirm_check:\n
item.confirm()\n item.confirm()\n
for j in reference_list:\n for j in reference_list:\n
#tag = \'check_%s_%s_%s\' % (model_uid, destination_payment_uid, j)\n
#encountered_check_identifiers_dict[tag] = None\n #encountered_check_identifiers_dict[tag] = None\n
check = item.newContent(portal_type=\'Check\', title=j, activate_kw={\'tag\': tag, \'priority\':4})\n check = item.newContent(portal_type=\'Check\', title=j, activate_kw={\'tag\': tag, \'priority\':4})\n
context.log(\'New Sub Item created with Id\', check.getId())\n context.log(\'New Sub Item created with Id\', check.getId())\n
...@@ -246,7 +245,7 @@ for i in xrange(quantity):\n ...@@ -246,7 +245,7 @@ for i in xrange(quantity):\n
else:\n else:\n
last_reference_value = reference_to_int(reference_range_min)\n last_reference_value = reference_to_int(reference_range_min)\n
if check == 1:\n if check == 1:\n
checkReferenceUniqueness(reference_range_min, model_uid, destination_payment_uid, unique_per_account)\n checkReferenceListUniqueness([reference_range_min, ], model_uid, destination_payment_value, unique_per_account)\n
if create == 1:\n if create == 1:\n
item.setReference(reference_range_min)\n item.setReference(reference_range_min)\n
item.setResource(model)\n item.setResource(model)\n
...@@ -258,7 +257,6 @@ for i in xrange(quantity):\n ...@@ -258,7 +257,6 @@ for i in xrange(quantity):\n
if confirm_check:\n if confirm_check:\n
item.setStartDate(start_date)\n item.setStartDate(start_date)\n
item.confirm()\n item.confirm()\n
#tag = \'check_%s_%s_%s\' % (model_uid, destination_payment_uid, reference_range_min)\n
#encountered_check_identifiers_dict[tag] = None\n #encountered_check_identifiers_dict[tag] = None\n
# update reference_range_min for the next pass\n # update reference_range_min for the next pass\n
reference_range_min = int_to_reference(last_reference_value + 1, reference_range_min)\n reference_range_min = int_to_reference(last_reference_value + 1, reference_range_min)\n
...@@ -343,7 +341,6 @@ return encountered_check_identifiers_dict\n ...@@ -343,7 +341,6 @@ return encountered_check_identifiers_dict\n
<string>generateTravelerCheckReference</string> <string>generateTravelerCheckReference</string>
<string>assertReferenceMatchListEmpty</string> <string>assertReferenceMatchListEmpty</string>
<string>checkReferenceListUniqueness</string> <string>checkReferenceListUniqueness</string>
<string>checkReferenceUniqueness</string>
<string>start_date</string> <string>start_date</string>
<string>destination</string> <string>destination</string>
<string>line</string> <string>line</string>
...@@ -366,7 +363,6 @@ return encountered_check_identifiers_dict\n ...@@ -366,7 +363,6 @@ return encountered_check_identifiers_dict\n
<string>destination_payment_value</string> <string>destination_payment_value</string>
<string>message</string> <string>message</string>
<string>ValueError</string> <string>ValueError</string>
<string>destination_payment_uid</string>
<string>destination_trade</string> <string>destination_trade</string>
<string>unique_per_account</string> <string>unique_per_account</string>
<string>aggregate_list</string> <string>aggregate_list</string>
......
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