From 5f38667c5bbc761951f66b637d298a42ec7dc48e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 31 May 2011 12:01:58 +0200
Subject: [PATCH] Create proper Packing List during requesting.

As Hosting Subscription is common document for all Software Instances used in
request process, use it to find common parameters of all deliveries.
---
 ...ubscription_getInstancePackingListLine.xml | 107 ++++++++++++++++++
 ...twareInstance_requestComputerPartition.xml |  17 ++-
 master/bt5/vifib_base/bt/revision             |   2 +-
 3 files changed, 122 insertions(+), 4 deletions(-)
 create mode 100644 master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/HostingSubscription_getInstancePackingListLine.xml

diff --git a/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/HostingSubscription_getInstancePackingListLine.xml b/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/HostingSubscription_getInstancePackingListLine.xml
new file mode 100644
index 000000000..dd5b8c885
--- /dev/null
+++ b/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/HostingSubscription_getInstancePackingListLine.xml
@@ -0,0 +1,107 @@
+<?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>software_instance = state_change[\'object\']\n
+hosting_subscription_uid = state_change.kwargs[\'hosting_subscription_uid\']\n
+hosting_subscription = software_instance.portal_catalog.getResultValue(uid=hosting_subscription_uid)\n
+portal = software_instance.getPortalObject()\n
+\n
+# Get services\n
+portal_preferences = portal.portal_preferences\n
+service_uid_list = []\n
+\n
+if service_relative_url is None:\n
+  for service_relative_url in \\\n
+    (portal_preferences.getPreferredInstanceSetupResource(),\n
+     portal_preferences.getPreferredInstanceHostingResource(),\n
+     portal_preferences.getPreferredInstanceCleanupResource(),\n
+     ):\n
+    service = portal.restrictedTraverse(service_relative_url)\n
+    service_uid_list.append(service.getUid())\n
+else:\n
+  service = portal.restrictedTraverse(service_relative_url)\n
+  service_uid_list.append(service.getUid())\n
+\n
+# Packing List valid state\n
+state_list = []\n
+state_list.extend(portal.getPortalReservedInventoryStateList())\n
+state_list.extend(portal.getPortalTransitInventoryStateList())\n
+state_list.extend(portal.getPortalCurrentInventoryStateList())\n
+\n
+packing_list_line = portal.portal_catalog.getResultValue(\n
+  portal_type=\'Sale Packing List Line\',\n
+  simulation_state=state_list,\n
+  aggregate_uid=hosting_subscription_uid,\n
+  default_resource_uid=service_uid_list,\n
+  sort_on=((\'movement.start_date\', \'DESC\'),),\n
+  limit=1,\n
+)\n
+\n
+if packing_list_line is None:\n
+  raise ValueError("No sale packing list line found for %s" % \\\n
+        hosting_subscription.getRelativeUrl())\n
+else:\n
+  return packing_list_line\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>state_change, service_relative_url=None</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>HostingSubscription_getInstancePackingListLine</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/SoftwareInstance_requestComputerPartition.xml b/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/SoftwareInstance_requestComputerPartition.xml
index adecfbb50..0d53d00f3 100644
--- a/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/SoftwareInstance_requestComputerPartition.xml
+++ b/master/bt5/vifib_base/WorkflowTemplateItem/portal_workflow/software_instance_slap_interface_workflow/scripts/SoftwareInstance_requestComputerPartition.xml
@@ -146,11 +146,22 @@ software_release_document = context.portal_catalog.getResultValue(\n
 # protect computer partition from being selected again\n
 portal = context.getPortalObject()\n
 \n
+hosting_subscription = software_instance.portal_catalog.getResultValue(uid=hosting_subscription_uid)\n
+sale_packing_list_line = context.HostingSubscription_getInstancePackingListLine(state_change)\n
+base_sale_packing_list = sale_packing_list_line.getParentValue()\n
 # XXX: SoftwareInstance_createSalePackingList shall be used to create new Sale Packing List\n
 sale_packing_list_module = portal.getDefaultModule(portal_type=\'Sale Packing List\')\n
-sale_packing_list = sale_packing_list_module.newContent(portal_type=\'Sale Packing List\', \n
-                                                        start_date=DateTime())\n
-hosting_subscription = software_instance.portal_catalog.getResultValue(uid=hosting_subscription_uid)\n
+\n
+sale_packing_list = sale_packing_list_module.newContent(\n
+  portal_type=\'Sale Packing List\', \n
+  start_date=DateTime(),\n
+  specialise=base_sale_packing_list.getSpecialise() or base_sale_packing_list.getCausalityValue().getSpecialise(),\n
+  destination=base_sale_packing_list.getDestination(),\n
+  destination_section=base_sale_packing_list.getDestinationSection(),\n
+  destination_decision=base_sale_packing_list.getDestinationDecision(),\n
+  source=base_sale_packing_list.getSource(),\n
+  source_section=base_sale_packing_list.getSourceSection(),\n
+  price_currency=base_sale_packing_list.getPriceCurrency())\n
 sale_packing_list_line = sale_packing_list.newContent(\n
   portal_type=\'Sale Packing List Line\',\n
   resource=context.portal_preferences.getPreferredInstanceSetupResource(),\n
diff --git a/master/bt5/vifib_base/bt/revision b/master/bt5/vifib_base/bt/revision
index b3b2268d2..d903d5972 100644
--- a/master/bt5/vifib_base/bt/revision
+++ b/master/bt5/vifib_base/bt/revision
@@ -1 +1 @@
-228
\ No newline at end of file
+229
\ No newline at end of file
-- 
2.30.9