Commit e6aa7509 authored by Aurel's avatar Aurel

Prevent from deleting lines which have activities on them or their content:

- Define variation_not_defined missing at top level
- Factorise line deletion code
- Make recursive checks on deleted document to check for activity presence
- Only execute document creation code if deletion ended without error
- Move pre-error-exit line deletion to code branch creating new lines
- Add a new error message when there are pending activities (only displays the first activity found)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20320 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 99dfbe3a
......@@ -73,6 +73,26 @@ ADD_PERMISSION = \'Add portal content\'\n
if not u.has_permission(ADD_PERMISSION,context):\n
raise ValueError, "How did you manage to be there ???"\n
\n
request = context.REQUEST\n
N_ = context.Base_translateString\n
\n
def recurse(document):\n
result = document.hasActivity()\n
if not result:\n
for subdocument in document.objectValues():\n
result = recurse(subdocument)\n
if result:\n
break\n
return result\n
\n
def deleteContent(container, document_id):\n
document = container[document_id]\n
if recurse(document):\n
return True\n
else:\n
container.deleteContent(document_id)\n
return False\n
\n
cell_base_id = \'movement\'\n
line_kwd = {\'base_id\':cell_base_id}\n
\n
......@@ -101,21 +121,24 @@ per_resource_dict = {}\n
error = 0\n
negative_quantity = 0\n
float_quantity = 0\n
variation_not_defined = 0\n
remaining_activity = None\n
# remove previous line\n
# specific case for monetary issue\n
if context.getPortalType() == "Monetary Issue":\n
old_line = [id for id in context.objectIds()]\n
if len(old_line)>0:\n
for line_id in old_line:\n
context.deleteContent(line_id)\n
else:\n
old_line = [x.getObject().getId() for x in context.objectValues(portal_type=[line_portal_type,])]\n
if len(old_line)>0:\n
if len(old_line)>0:\n
for line_id in old_line:\n
context.deleteContent(line_id)\n
if deleteContent(context, line_id):\n
error = 1\n
remaining_activity = \'%s/%s\' % (context.getPath(), line_id)\n
break\n
\n
# get the list of movement we need to create\n
for line in listbox:\n
if not error:\n
# get the list of movement we need to create\n
for line in listbox:\n
for counter in xrange(1, len(column_base_list)+1):\n
quantity = line["column%s" %(str(counter),)]\n
if quantity != 0 and quantity != \'\':\n
......@@ -186,10 +209,10 @@ for line in listbox:\n
else:\n
# create a dict of variation for this resource\n
per_resource_dict[resource_id] = {movement_key:movement,}\n
#context.log("resource", per_resource_dict)\n
# create the movement\n
variation_not_defined = 0\n
for resource_id in per_resource_dict.keys():\n
#context.log("resource", per_resource_dict)\n
# create the movement\n
variation_not_defined = 0\n
for resource_id in per_resource_dict.keys():\n
if error == 1:\n
break\n
variation_list_dict = per_resource_dict[resource_id].values()\n
......@@ -209,9 +232,9 @@ for resource_id in per_resource_dict.keys():\n
variation = variation[\'variation\']\n
# check if variation exist for the resource\n
if column_base_category == "variation":\n
# if variation != \'variation/not_defined\' and variation.replace(\'variation/\',\'\') not in resource_object.getVariationList():\n
# variation_not_defined = 1\n
# break\n
# if variation != \'variation/not_defined\' and variation.replace(\'variation/\',\'\') not in resource_object.getVariationList():\n
# variation_not_defined = 1\n
# break\n
if variation.replace(\'variation/\',\'\') not in resource_object.getVariationList():\n
variation_not_defined = 1\n
error = 1\n
......@@ -299,21 +322,23 @@ for resource_id in per_resource_dict.keys():\n
cell.setQuantity(variation_item["quantity"])\n
line.getPrice() # Call getPrice now because it will be called on reindexation and it modifies the line.\n
# So better modify it here so it\'s only saved once to ZODB.\n
\n
request = context.REQUEST\n
N_ = context.Base_translateString\n
\n
if error:\n
if error:\n
# Delete what was already created\n
old_line = [x.getObject() for x in context.objectValues(portal_type=[line_portal_type,])]\n
if len(old_line)>0:\n
for object_list in old_line:\n
context.deleteContent(object_list.getId())\n
\n
\n
if error:\n
if variation_not_defined:\n
message = N_("$title doesn\'t exist for $variation", mapping = {\'title\':resource_object.getTranslatedTitle(), \'variation\':variation.replace(\'variation/\',\'\')})\n
if negative_quantity:\n
message = N_("You must not enter negative values")\n
if float_quantity:\n
message = N_("You must enter integer values")\n
if remaining_activity is not None:\n
message = N_("There are operations pending on $path. Please try again later.", mapping={\'path\': remaining_activity})\n
redirect_url = \'%s/view?%s\' % ( context.absolute_url()\n
, "portal_status_message=%s" %message\n
)\n
......@@ -392,6 +417,10 @@ else:\n
<string>ADD_PERMISSION</string>
<string>context</string>
<string>ValueError</string>
<string>request</string>
<string>N_</string>
<string>recurse</string>
<string>deleteContent</string>
<string>cell_base_id</string>
<string>line_kwd</string>
<string>_getitem_</string>
......@@ -413,14 +442,17 @@ else:\n
<string>error</string>
<string>negative_quantity</string>
<string>float_quantity</string>
<string>variation_not_defined</string>
<string>None</string>
<string>remaining_activity</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>id</string>
<string>old_line</string>
<string>x</string>
<string>len</string>
<string>line_id</string>
<string>x</string>
<string>line</string>
<string>xrange</string>
<string>counter</string>
......@@ -430,7 +462,6 @@ else:\n
<string>_write_</string>
<string>movement_key</string>
<string>resource_id</string>
<string>variation_not_defined</string>
<string>variation_list_dict</string>
<string>resource_object</string>
<string>emission_letter_dict</string>
......@@ -444,7 +475,6 @@ else:\n
<string>key</string>
<string>variation_category_list</string>
<string>cell_range_key_list</string>
<string>None</string>
<string>k</string>
<string>filter</string>
<string>category_list</string>
......@@ -453,8 +483,6 @@ else:\n
<string>mapped_value_list</string>
<string>variation_item</string>
<string>cell</string>
<string>request</string>
<string>N_</string>
<string>object_list</string>
<string>message</string>
<string>redirect_url</string>
......
429
\ No newline at end of file
430
\ 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