<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string>from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, NegatedQuery\n
\n
current_delivery = state_change[\'object\']\n
portal = current_delivery.getPortalObject()\n
\n
destroy_service_relative_url = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
\n
sale_packing_list_line_list = current_delivery.contentValues(portal_type="Sale Packing List Line")\n
assert len(sale_packing_list_line_list) == 1\n
current_delivery_line = sale_packing_list_line_list[0]\n
if current_delivery_line.getResource() != destroy_service_relative_url:\n
  return\n
\n
computer_partition = current_delivery_line.getAggregateValue(portal_type=["Computer Partition", "Slave Partition"])\n
if computer_partition is None:\n
  raise ValueError("Sale Packing List Line \'%s\' should have a computer partition aggregated" % current_delivery_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
# Deliver all SPL related to this software instance\n
software_instance = current_delivery_line.getAggregateValue(portal_type="Software Instance")\n
for sale_packing_list_line in portal.portal_catalog(\n
  portal_type="Sale Packing List Line", \n
  default_aggregate_uid=software_instance.getUid(),\n
  simulation_state=NegatedQuery(Query(simulation_state="delivered")),\n
  ):\n
  sale_packing_list = sale_packing_list_line.getParentValue()\n
  if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'start\'):\n
    sale_packing_list.start()\n
  if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'stop\'):\n
    sale_packing_list.stop()\n
  if sale_packing_list.getPortalObject().portal_workflow.isTransitionPossible(sale_packing_list, \'deliver\'):\n
    sale_packing_list.deliver()\n
  if sale_packing_list.getSimulationState() != \'delivered\':\n
    raise ValueError(\'It was not possible to deliver %r during destruction of %r\' % (sale_packing_list.getRelativeUrl(), software_instance.getRelativeUrl()))\n
# Remove unused open sale order line\n
subscription_item = sale_packing_list_line.getAggregateValue(portal_type="Hosting Subscription")\n
subscription_item.HostingSubscription_removeRelatedOpenSaleOrderLine()\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>state_change</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>SalePackingList_markComputerPartitionFree</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
