Commit 52d4fa81 authored by Vincent Pelletier's avatar Vincent Pelletier

Revert the previous changes : the right way is not to generate additionnal...

Revert the previous changes : the right way is not to generate additionnal lines, but to offer the possibility to input the check reference range end in the case of a traveler check.
Factorise new code with existing one.
Add a check to avoid a "substracting str to str" error when converting the check reference to int fails.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13273 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f4de1744
...@@ -102,39 +102,33 @@ def generate_error(listbox_line, column_title, error_message):\n ...@@ -102,39 +102,33 @@ def generate_error(listbox_line, column_title, error_message):\n
field_error_dict[error_id] = error\n field_error_dict[error_id] = error\n
error_value = 1\n error_value = 1\n
\n \n
def convertTravelerCheckReferenceToInt(traveler_check_reference):\n
"""\n
Convert a reaveler check reference into an int.\n
Raise ValueError if traveler_check_reference doesn\'t have a valid format.\n
"""\n
if not same_type(traveler_check_reference, \'\'):\n
raise ValueError\n
if len(traveler_check_reference) != 10:\n
raise ValueError\n
return int(traveler_check_reference[4:])\n
\n \n
# listbox is not passed at the first time when this script is called.\n # listbox is not passed at the first time when this script is called.\n
# when the user clicks on the Update button, listbox is passed, and\n # when the user clicks on the Update button, listbox is passed, and\n
# the contents must be preserved in the form.\n # the contents must be preserved in the form.\n
new_listbox = []\n
if listbox in (None,()) or (previous_resource not in(\'\',None) and previous_resource!=resource):\n if listbox in (None,()) or (previous_resource not in(\'\',None) and previous_resource!=resource):\n
listbox = []\n
for i in range(0,10):\n for i in range(0,10):\n
#listbox.append({\'quantity\':1,\'uid\':\'new_%03i\' % i})\n #listbox.append({\'quantity\':1,\'uid\':\'new_%03i\' % i})\n
new_listbox.append({\'quantity\':1})\n listbox.append({\'quantity\':1})\n
\n \n
else:\n else:\n
for line in listbox:\n for line in listbox:\n
new_listbox.append(line) # Add line from the begining. All changes in the loop will apply to the appended object (pointer).\n
destination_payment_reference = line.get(\'destination_payment_reference\',None)\n destination_payment_reference = line.get(\'destination_payment_reference\',None)\n
reference_range_min = line.get(\'reference_range_min\',None)\n reference_range_min = line.get(\'reference_range_min\',None)\n
reference_range_max = line.get(\'reference_range_max\',None)\n reference_range_max = line.get(\'reference_range_max\',None)\n
check_amount = line.get(\'check_amount\',None)\n check_amount = line.get(\'check_amount\',None)\n
quantity = int(line.get(\'quantity\',0))\n quantity = int(line.get(\'quantity\',0))\n
if item_model.isFixedPrice():\n
if quantity > 1:\n
try:\n
if len(reference_range_min) != 10:\n
raise ValueError, \'Reference must be 10 char long.\'\n
reference_numeric_part = int(reference_range_min[4:])\n
except ValueError, message:\n
generate_error(line, \'reference_range_min\', \'Reference format unrecognized: %s\' % (message, ))\n
else:\n
reference_prefix = reference_range_min[:4]\n
line[\'quantity\'] = 1\n
for increment in xrange(quantity):\n
new_line = line.copy()\n
new_line[\'reference_range_min\'] = \'%s%06d\' % (reference_prefix, reference_numeric_part + increment + 1)\n
new_listbox.append(new_line)\n
if destination_payment_reference not in (None,\'\'):\n if destination_payment_reference not in (None,\'\'):\n
account_list = [x.getObject() for x in\n account_list = [x.getObject() for x in\n
context.portal_catalog(portal_type=\'Bank Account\',\n context.portal_catalog(portal_type=\'Bank Account\',\n
...@@ -161,40 +155,38 @@ else:\n ...@@ -161,40 +155,38 @@ else:\n
#reference_range_max = reference_range_min\n #reference_range_max = reference_range_min\n
#line[\'reference_range_max\'] = reference_range_max\n #line[\'reference_range_max\'] = reference_range_max\n
if reference_range_min not in (None,\'\') and reference_range_max not in (None,\'\'):\n if reference_range_min not in (None,\'\') and reference_range_max not in (None,\'\'):\n
check_quantity = 1\n if item_model.isFixedPrice():\n
check_reference=1\n convert_func = convertTravelerCheckReferenceToInt\n
if not item_model.isFixedPrice():\n value_denomination = \'traveler check reference\'\n
else:\n
convert_func = int\n
value_denomination = \'number\'\n
try:\n try:\n
reference_range_min = int(reference_range_min)\n reference_range_min = convert_func(reference_range_min)\n
except ValueError:\n except ValueError:\n
message = \'This number is not valid\'\n generate_error(line, \'reference_range_min\', \'%s is not a valid %s\' % (reference_range_min, value_denomination))\n
generate_error(line,\'reference_range_min\',message)\n
try:\n try:\n
reference_range_max = int(reference_range_max)\n reference_range_max = convert_func(reference_range_max)\n
except ValueError:\n except ValueError:\n
message = \'This number is not valid\'\n generate_error(line, \'reference_range_max\', \'%s is not a valid %s\' % (reference_range_max, value_denomination))\n
generate_error(line,\'reference_range_max\',message)\n
else:\n
check_reference = 0\n
if check_amount is not None: # In the case of a check book\n if check_amount is not None: # In the case of a check book\n
check_amount_relative_url = \'/\'.join(check_amount.split(\'/\')[1:])\n check_amount_relative_url = \'/\'.join(check_amount.split(\'/\')[1:])\n
line[\'check_amount_relative_url\'] = check_amount_relative_url\n line[\'check_amount_relative_url\'] = check_amount_relative_url\n
check_amount_value = context.getPortalObject().restrictedTraverse(check_amount_relative_url)\n check_amount_value = context.getPortalObject().restrictedTraverse(check_amount_relative_url)\n
check_quantity = int(check_amount_value.getQuantity())\n check_quantity = int(check_amount_value.getQuantity())\n
if check_reference:\n else:\n
if (reference_range_max-reference_range_min+1)!=(check_quantity*quantity):\n check_quantity = 1\n
if same_type(reference_range_min, 0) and \\\n
same_type(reference_range_max, 0) and \\\n
reference_range_max - reference_range_min + 1 != check_quantity * quantity:\n
message = \'The range is not valid\'\n message = \'The range is not valid\'\n
generate_error(line,\'reference_range_min\',message)\n generate_error(line,\'reference_range_min\',message)\n
generate_error(line,\'reference_range_max\',message)\n generate_error(line,\'reference_range_max\',message)\n
\n \n
# Update all listbox_keys\n
for line_index in xrange(len(new_listbox)):\n
new_listbox[line_index][\'listbox_key\'] = \'%03d\' % (line_index, )\n
\n
if batch_mode:\n if batch_mode:\n
return error_value\n return error_value\n
else:\n else:\n
context.Base_updateDialogForm(listbox=new_listbox\n context.Base_updateDialogForm(listbox=listbox\n
, portal_type = context.getPortalType()\n , portal_type = context.getPortalType()\n
, resource=resource\n , resource=resource\n
, previous_resource=resource\n , previous_resource=resource\n
...@@ -277,7 +269,7 @@ else:\n ...@@ -277,7 +269,7 @@ else:\n
<string>error_value</string> <string>error_value</string>
<string>field_error_dict</string> <string>field_error_dict</string>
<string>generate_error</string> <string>generate_error</string>
<string>new_listbox</string> <string>convertTravelerCheckReferenceToInt</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>range</string> <string>range</string>
<string>i</string> <string>i</string>
...@@ -288,27 +280,23 @@ else:\n ...@@ -288,27 +280,23 @@ else:\n
<string>check_amount</string> <string>check_amount</string>
<string>int</string> <string>int</string>
<string>quantity</string> <string>quantity</string>
<string>len</string>
<string>ValueError</string>
<string>_getitem_</string>
<string>reference_numeric_part</string>
<string>message</string>
<string>reference_prefix</string>
<string>_write_</string>
<string>xrange</string>
<string>increment</string>
<string>new_line</string>
<string>append</string> <string>append</string>
<string>$append0</string> <string>$append0</string>
<string>x</string> <string>x</string>
<string>account_list</string> <string>account_list</string>
<string>len</string>
<string>message</string>
<string>_getitem_</string>
<string>account</string> <string>account</string>
<string>_write_</string>
<string>destination_trade</string> <string>destination_trade</string>
<string>check_quantity</string> <string>convert_func</string>
<string>check_reference</string> <string>value_denomination</string>
<string>ValueError</string>
<string>check_amount_relative_url</string> <string>check_amount_relative_url</string>
<string>check_amount_value</string> <string>check_amount_value</string>
<string>line_index</string> <string>check_quantity</string>
<string>same_type</string>
<string>_apply_</string> <string>_apply_</string>
</tuple> </tuple>
</value> </value>
......
...@@ -88,7 +88,6 @@ if item_model.getPortalType()== \'Check Model\':\n ...@@ -88,7 +88,6 @@ if item_model.getPortalType()== \'Check Model\':\n
if len(item_model.getVariationRangeCategoryList())>0:\n if len(item_model.getVariationRangeCategoryList())>0:\n
return_list.append([\'check_type\',\'Check Value\'])\n return_list.append([\'check_type\',\'Check Value\'])\n
return_list.append([\'reference_range_min\',\'Start Number\'])\n return_list.append([\'reference_range_min\',\'Start Number\'])\n
if not item_model.isFixedPrice():\n
return_list.append([\'reference_range_max\',\'Stop Number\'])\n return_list.append([\'reference_range_max\',\'Stop Number\'])\n
\n \n
if item_model.getPortalType()== \'Checkbook Model\':\n if item_model.getPortalType()== \'Checkbook Model\':\n
......
87 89
\ 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