Commit d1a93516 authored by Łukasz Nowak's avatar Łukasz Nowak

- simplify logic and put assertions instead of error prone iterations

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43989 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7da1d23d
...@@ -52,52 +52,54 @@ ...@@ -52,52 +52,54 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, NegatedQuery\n <value> <string>from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, NegatedQuery\n
\n \n
sale_packing_list = state_change[\'object\']\n current_delivery = state_change[\'object\']\n
portal = sale_packing_list.getPortalObject()\n portal = current_delivery.getPortalObject()\n
\n \n
destroy_service_relative_url = sale_packing_list.portal_preferences.getPreferredInstanceCleanupResource()\n destroy_service_relative_url = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
\n \n
for sale_packing_list_line in sale_packing_list.contentValues(\n sale_packing_list_line_list = current_delivery.contentValues(portal_type="Sale Packing List Line")\n
portal_type="Sale Packing List Line"):\n assert len(sale_packing_list_line_list) == 1\n
if sale_packing_list_line.getResource() == destroy_service_relative_url:\n current_delivery_line = sale_packing_list_line_list[0]\n
computer_partition = sale_packing_list_line.getAggregateValue(portal_type=["Computer Partition", "Slave Partition"])\n assert current_delivery_line == destroy_service_relative_url\n
if computer_partition is None:\n
raise ValueError("Sale Packing List Line \'%s\' should have a computer partition aggregated" % sale_packing_list_line.getRelativeUrl())\n
else:\n
# Mark computer partition as free\n
# This method should be always callable in this step to prevent having 2 packing list related to the same computer partition\n
computer_partition.markFree()\n
\n \n
# Deliver all SPL related to this software instance\n computer_partition = current_delivery_line.getAggregateValue(portal_type=["Computer Partition", "Slave Partition"])\n
software_instance = sale_packing_list_line.getAggregateValue(portal_type="Software Instance")\n if computer_partition is None:\n
for sale_packing_list_line in portal.portal_catalog(\n raise ValueError("Sale Packing List Line \'%s\' should have a computer partition aggregated" % current_delivery_line.getRelativeUrl())\n
portal_type="Sale Packing List Line", \n else:\n
default_aggregate_uid=software_instance.getUid(),\n # Mark computer partition as free\n
simulation_state=NegatedQuery(Query(simulation_state="delivered")),\n # This method should be always callable in this step to prevent having 2 packing list related to the same computer partition\n
):\n computer_partition.markFree()\n
if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'start\'):\n \n
sale_packing_list.start()\n # Deliver all SPL related to this software instance\n
if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'stop\'):\n software_instance = current_delivery_line.getAggregateValue(portal_type="Software Instance")\n
sale_packing_list.stop()\n for sale_packing_list_line in portal.portal_catalog(\n
if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'deliver\'):\n portal_type="Sale Packing List Line", \n
sale_packing_list.deliver()\n default_aggregate_uid=software_instance.getUid(),\n
if sale_packing_list.getSimulationState() != \'delivered\':\n simulation_state=NegatedQuery(Query(simulation_state="delivered")),\n
raise ValueError(\'It was not possible to deliver %r during destruction of %r\' (sale_packing_list.getRelativeUrl(), software_instance.getRelativeUrl()))\n ):\n
# Remove unused open sale order line\n if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'start\'):\n
subscription_item = sale_packing_list_line.getAggregateValue(portal_type="Hosting Subscription")\n sale_packing_list.start()\n
all_delivered = True\n if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'stop\'):\n
for sale_packing_list_line in portal.portal_catalog(\n sale_packing_list.stop()\n
portal_type="Sale Packing List Line", \n if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'deliver\'):\n
default_aggregate_uid=subscription_item.getUid(),\n sale_packing_list.deliver()\n
simulation_state=NegatedQuery(Query(simulation_state="delivered")),\n if sale_packing_list.getSimulationState() != \'delivered\':\n
):\n raise ValueError(\'It was not possible to deliver %r during destruction of %r\' (sale_packing_list.getRelativeUrl(), software_instance.getRelativeUrl()))\n
if sale_packing_list_line.getSimulationState() != \'delivered\':\n # Remove unused open sale order line\n
all_delivered = False\n subscription_item = sale_packing_list_line.getAggregateValue(portal_type="Hosting Subscription")\n
if all_delivered:\n all_delivered = True\n
open_order_line = subscription_item.getAggregateRelatedValue(portal_type="Open Sale Order Line")\n for sale_packing_list_line in portal.portal_catalog(\n
if open_order_line is not None:\n portal_type="Sale Packing List Line", \n
# XXX: Mahybe system shall *NOT* work without Open Sale Orders\n default_aggregate_uid=subscription_item.getUid(),\n
open_order_line.getParentValue().manage_delObjects(open_order_line.getId())\n simulation_state=NegatedQuery(Query(simulation_state="delivered")),\n
):\n
if sale_packing_list_line.getSimulationState() != \'delivered\':\n
all_delivered = False\n
if all_delivered:\n
open_order_line = subscription_item.getAggregateRelatedValue(portal_type="Open Sale Order Line")\n
if open_order_line is not None:\n
# XXX: Mahybe system shall *NOT* work without Open Sale Orders\n
open_order_line.getParentValue().manage_delObjects(open_order_line.getId())\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -140,16 +142,21 @@ for sale_packing_list_line in sale_packing_list.contentValues(\n ...@@ -140,16 +142,21 @@ for sale_packing_list_line in sale_packing_list.contentValues(\n
<string>ComplexQuery</string> <string>ComplexQuery</string>
<string>NegatedQuery</string> <string>NegatedQuery</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>sale_packing_list</string> <string>current_delivery</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>portal</string> <string>portal</string>
<string>destroy_service_relative_url</string> <string>destroy_service_relative_url</string>
<string>_getiter_</string> <string>sale_packing_list_line_list</string>
<string>sale_packing_list_line</string> <string>len</string>
<string>AssertionError</string>
<string>current_delivery_line</string>
<string>computer_partition</string> <string>computer_partition</string>
<string>None</string> <string>None</string>
<string>ValueError</string> <string>ValueError</string>
<string>software_instance</string> <string>software_instance</string>
<string>_getiter_</string>
<string>sale_packing_list_line</string>
<string>sale_packing_list</string>
<string>subscription_item</string> <string>subscription_item</string>
<string>True</string> <string>True</string>
<string>all_delivered</string> <string>all_delivered</string>
......
357 358
\ 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