Commit b1e4429d authored by Antoine Catton's avatar Antoine Catton

Adapt HostingSubscription_requestRootSoftwareInstance to new request logic.

parent 6a4aed6e
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n from DateTime import DateTime\n
from Products.ERP5Type.DateUtils import getClosestDate, addToDate\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
cleanup_resource = portal.portal_preferences.getPreferredInstanceCleanupResource()\n cleanup_resource = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
...@@ -63,109 +64,145 @@ if (portal.portal_activities.countMessageWithTag(tag) > 0):\n ...@@ -63,109 +64,145 @@ if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
# The software instance is already under creation but can not be fetched from catalog\n # The software instance is already under creation but can not be fetched from catalog\n
# As it is not possible to fetch informations, it is better to raise an error\n # As it is not possible to fetch informations, it is better to raise an error\n
raise NotImplementedError(tag)\n raise NotImplementedError(tag)\n
hosting_subscription = context\n
\n \n
sale_order_portal_type = "Sale Order"\n sale_order_portal_type = "Sale Order"\n
sale_order_line_portal_type = "Sale Order Line"\n sale_order_line_portal_type = "Sale Order Line"\n
hosting_subscription_portal_type = "Hosting Subscription"\n hosting_subscription_portal_type = "Hosting Subscription"\n
if context.isRootSlave():\n if hosting_subscription.isRootSlave():\n
software_instance_portal_type = "Slave Instance"\n software_instance_portal_type = "Slave Instance"\n
else:\n else:\n
software_instance_portal_type = "Software Instance"\n software_instance_portal_type = "Software Instance"\n
\n \n
# Mostly copy and paste from\n # Mostly copy and paste from\n
# portal_workflow/person_slap_interface_workflow/scripts/Person_requestSoftwareInstance\n # portal_workflow/person_slap_interface_workflow/scripts/Person_requestSoftwareInstance\n
request_software_instance = context.portal_catalog.getResultValue(\n request_software_instance = hosting_subscription.portal_catalog.getResultValue(\n
portal_type=software_instance_portal_type,\n portal_type=software_instance_portal_type,\n
title=context.getTitle(),\n title=hosting_subscription.getTitle(),\n
root_uid=context.getUid(),\n root_uid=hosting_subscription.getUid(),\n
)\n )\n
\n \n
if request_software_instance is None:\n if person is None:\n
setup_service_relative_url = portal.portal_preferences.getPreferredInstanceSetupResource()\n open_sale_order_line = hosting_subscription.portal_catalog.getResultValue(\n
portal_type=\'Open Sale Order Line\', strict_aggregate_uid=hosting_subscription.getUid())\n
open_sale_order = open_sale_order_line.getParentValue()\n
person = open_sale_order.getDestinationSectionValue()\n
\n \n
new_one = False\n
if (request_software_instance is None):\n
new_one = True\n
setup_service_relative_url = portal.portal_preferences.getPreferredInstanceSetupResource()\n
request_software_instance = portal.getDefaultModule(portal_type=software_instance_portal_type).newContent(\n request_software_instance = portal.getDefaultModule(portal_type=software_instance_portal_type).newContent(\n
portal_type=software_instance_portal_type,\n portal_type=software_instance_portal_type,\n
source_reference=context.getSourceReference(),\n source_reference=hosting_subscription.getSourceReference(),\n
title=context.getTitle(),\n title=hosting_subscription.getTitle(),\n
text_content=context.getTextContent(),\n text_content=hosting_subscription.getTextContent(),\n
sla_xml=context.getSlaXml(),\n sla_xml=hosting_subscription.getSlaXml(),\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag},\n
**portal.Base_getNewSoftwareInstanceCoordinate()\n **portal.Base_getNewSoftwareInstanceCoordinate()\n
)\n )\n
request_software_instance.portal_workflow.doActionFor(request_software_instance, \'validate_action\')\n request_software_instance.portal_workflow.doActionFor(request_software_instance,\n
context.setPredecessorValueList(\n \'validate_action\')\n
context.getPredecessorValueList() + [request_software_instance]\n
)\n
\n \n
if not person_request:\n
packing_list_line = software_instance.getAggregateRelatedValue(portal_type="Sale Packing List Line")\n
software_release_document = context.portal_catalog.getResultValue(\n software_release_document = context.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n portal_type=\'Software Release\',\n
url_string=context.getRootSoftwareRelease())\n url_string=hosting_subscription.getRootSoftwareReleaseUrl())\n
base_sale_packing_list = packing_list_line.getParentValue()\n \n
trade_condition = packing_list_line.getSpecialise(portal_type="Sale Trade Condition")\n sale_order = portal.getDefaultModule(portal_type=sale_order_portal_type).newContent(\n
sale_order = portal.getDefaultModule(portal_type="Sale Order").newContent(\n portal_type=sale_order_portal_type,\n
portal_type="Sale Order",\n destination_value=person,\n
destination=base_sale_packing_list.getDestination(),\n destination_section_value=person,\n
destination_section=base_sale_packing_list.getDestinationSection(),\n destination_decision_value=person,\n
destination_decision=base_sale_packing_list.getDestinationDecision(),\n
start_date=DateTime(),\n start_date=DateTime(),\n
received_date=DateTime(),\n received_date=DateTime(),\n
# XXX Hardcoded values\n # XXX Hardcoded values\n
source="organisation_module/vifib_internet",\n source="organisation_module/vifib_internet",\n
source_section="organisation_module/vifib_internet",\n source_section="organisation_module/vifib_internet",\n
quantity_unit="unit/piece",\n
price_currency="currency_module/EUR",\n price_currency="currency_module/EUR",\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag},\n
)\n )\n
\n
setup_service_relative_url = portal.portal_preferences.getPreferredInstanceSetupResource()\n
sale_order.setSpecialise(trade_condition, portal_type="Sale Trade Condition")\n
sale_order_line = sale_order.newContent(\n sale_order_line = sale_order.newContent(\n
portal_type="Sale Order Line",\n portal_type=sale_order_line_portal_type,\n
resource=setup_service_relative_url,\n resource=setup_service_relative_url,\n
quantity=1,\n quantity=1,\n
aggregate_value_list=[request_software_instance,context,software_release_document],\n price=0,\n
aggregate_value_list=[request_software_instance,\n
hosting_subscription,\n
software_release_document\n
],\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag},\n
)\n )\n
sale_order.order()\n portal.portal_workflow.doActionFor(sale_order, "order_action")\n
\n \n
if context.getRootState() == \'started\':\n # Update Open Order\n
request_software_instance.startRequested()\n # does this order have a client-specific Open Order\n
elif context.getRootState() == \'stopped\':\n open_order = portal.portal_catalog.getResultValue(\n
request_software_instance.stopRequested()\n default_destination_section_uid=person.getUid(),\n
portal_type="Open Sale Order",\n
validation_state="validated")\n
if open_order is None:\n
person_slap_interface_state = person.getSlapState()\n
if person_slap_interface_state == \'open_order_created\':\n
open_order_url = context.portal_workflow.getInfoFor(\n
ob=person, name=\'open_order_url\',\n
wf_id=\'person_slap_interface_workflow\')\n
open_order = portal.restrictedTraverse(open_order_url)\n
else:\n
raise ValueError(\'Person has no open order created\')\n
\n
now = DateTime()\n
start_date = getClosestDate(target_date=now, precision=\'day\', before=1)\n
# 12 months of subscription by default\n
stop_date = addToDate(getClosestDate(target_date=now, precision=\'month\', before=1), year=1)\n
\n
subscription_service_relative_url = portal.portal_preferences.getPreferredInstanceSubscriptionResource()\n
open_order.newContent(\n
portal_type="Open Sale Order Line",\n
title=hosting_subscription.getTitle(),\n
aggregate_value=hosting_subscription,\n
start_date=start_date,\n
stop_date=stop_date,\n
quantity=1,\n
quantity_unit="unit/piece",\n
price=1,\n
price_currency="currency_module/EUR",\n
specialise=sale_order.getSpecialise(portal_type="Sale Trade Condition"),\n
# XXX Hardcoded values\\n\n
resource=subscription_service_relative_url,\n
destination_value=person,\n
destination_section_value=person,\n
source="organisation_module/vifib_internet",\n
source_section="organisation_module/vifib_internet",\n
activate_kw={\'tag\': tag},\n
)\n
\n
# Find Computer partition\n
# XXX Link subscript to open order\n
else:\n else:\n
# Update existing software instance\n
request_software_instance.edit(\n request_software_instance.edit(\n
text_content=context.getTextContent(),\n text_content=hosting_subscription.getTextContent(),\n
source_reference=context.getSourceReference(),\n source_reference=hosting_subscription.getSourceReference(),\n
sla_xml=context.getSlaXml(),\n sla_xml=hosting_subscription.getSlaXml(),\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag},\n
)\n )\n
destroyed = False\n
try:\n
cleanup_delivery_line = request_software_instance.Item_getInstancePackingListLine(\n
portal.portal_preferences.getPreferredInstanceCleanupResource()\n
)\n
if cleanup_delivery_line.getSimulationState() == \'delivered\':\n
destroyed = True\n
except ValueError:\n
pass\n
\n \n
if not destroyed:\n if hosting_subscription.getRootState() == \'started\':\n
if context.getRootState() == \'started\':\n
request_software_instance.startRequested()\n request_software_instance.startRequested()\n
if not new_one:\n
request_software_instance.activate(after_tag=tag).requestStartComputerPartition()\n request_software_instance.activate(after_tag=tag).requestStartComputerPartition()\n
elif context.getRootState() == \'stopped\':\n elif hosting_subscription.getRootState() == \'stopped\':\n
request_software_instance.stopRequested()\n request_software_instance.stopRequested()\n
if not new_one:\n
request_software_instance.activate(after_tag=tag).requestStopComputerPartition()\n request_software_instance.activate(after_tag=tag).requestStopComputerPartition()\n
\n
return request_software_instance\n
]]></string> </value> ]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, person_request=False</string> </value> <value> <string>tag, person=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -52,8 +52,6 @@ ...@@ -52,8 +52,6 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n
from Products.ERP5Type.DateUtils import getClosestDate, addToDate\n
person = state_change[\'object\']\n person = state_change[\'object\']\n
portal = person.getPortalObject()\n portal = person.getPortalObject()\n
# Get required arguments\n # Get required arguments\n
...@@ -80,142 +78,54 @@ tag = "%s_%s_inProgress" % (person.getUid(), \n ...@@ -80,142 +78,54 @@ tag = "%s_%s_inProgress" % (person.getUid(), \n
\n \n
# Check if it already exists\n # Check if it already exists\n
cleanup_resource = portal.portal_preferences.getPreferredInstanceCleanupResource()\n cleanup_resource = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
request_software_instance = None\n request_hosting_subscription = None\n
for si in portal.portal_catalog(\n for hs in portal.portal_catalog(\n
portal_type=software_instance_portal_type,\n portal_type=hosting_subscription_portal_type,\n
title=software_title,\n title=software_title,\n
):\n ):\n
si = hs.portal_catalog.getResultValue(title=software_title,\n
root_uid=hs.getUid())\n
try:\n try:\n
cleanup_delivery_line = si.Item_getInstancePackingListLine(cleanup_resource)\n cleanup_delivery_line = si.Item_getInstancePackingListLine(cleanup_resource)\n
except ValueError:\n except ValueError:\n
request_software_instance = si\n request_hosting_subscription = hs\n
break\n break\n
else:\n else:\n
if cleanup_delivery_line.getSimulationState() != \'delivered\':\n if cleanup_delivery_line.getSimulationState() != \'delivered\':\n
request_software_instance = si\n request_hosting_subscription = hs\n
break\n break\n
\n \n
if (request_software_instance is None):\n if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
hosting_subscription_reference = "HOSTSUBS-%s" % context.getPortalObject().portal_ids\\\n
.generateNewId(id_group=\'slap_hosting_subscription_reference\', id_generator=\'uid\')\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
# The software instance is already under creation but can not be fetched from catalog\n # The software instance is already under creation but can not be fetched from catalog\n
# As it is not possible to fetch informations, it is better to raise an error\n # As it is not possible to fetch informations, it is better to raise an error\n
raise NotImplementedError(tag)\n raise NotImplementedError(tag)\n
else:\n
\n \n
setup_service_relative_url = portal.portal_preferences.getPreferredInstanceSetupResource()\n if (request_hosting_subscription is None):\n
software_instance = portal.getDefaultModule(portal_type=software_instance_portal_type).newContent(\n hosting_subscription_reference = "HOSTSUBS-%s" % context.getPortalObject().portal_ids\\\n
portal_type=software_instance_portal_type,\n .generateNewId(id_group=\'slap_hosting_subscription_reference\', id_generator=\'uid\')\n
source_reference=software_type,\n request_hosting_subscription = portal.getDefaultModule(portal_type=hosting_subscription_portal_type).newContent(\n
title=software_title,\n
text_content=instance_xml,\n
sla_xml=sla_xml,\n
activate_kw={\'tag\': tag},\n
**portal.Base_getNewSoftwareInstanceCoordinate()\n
)\n
software_instance.portal_workflow.doActionFor(software_instance, \'validate_action\')\n
subscription = portal.getDefaultModule(portal_type=hosting_subscription_portal_type).newContent(\n
portal_type=hosting_subscription_portal_type,\n portal_type=hosting_subscription_portal_type,\n
reference=hosting_subscription_reference,\n reference=hosting_subscription_reference,\n
title=software_title,\n title=software_title,\n
source_reference=software_type,\n
text_content=instance_xml,\n
sla_xml=sla_xml,\n
periodicity_hour_list=[0],\n periodicity_hour_list=[0],\n
periodicity_minute_list=[0],\n periodicity_minute_list=[0],\n
periodicity_month_day=[1],\n periodicity_month_day=[1],\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag},\n
)\n )\n
subscription.portal_workflow.doActionFor(subscription, \'validate_action\')\n request_hosting_subscription.portal_workflow.doActionFor(request_hosting_subscription,\n
if state == \'started\':\n \'validate_action\')\n
software_instance.startRequested()\n
elif state == \'stopped\':\n
software_instance.stopRequested()\n
\n
software_release_document = context.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n
url_string=software_release_url_string)\n
\n
sale_order = portal.getDefaultModule(portal_type=sale_order_portal_type).newContent(\n
portal_type=sale_order_portal_type,\n
destination_value=person,\n
destination_section_value=person,\n
destination_decision_value=person,\n
start_date=DateTime(),\n
received_date=DateTime(),\n
# XXX Hardcoded values\n
source="organisation_module/vifib_internet",\n
source_section="organisation_module/vifib_internet",\n
quantity_unit="unit/piece",\n
price_currency="currency_module/EUR",\n
activate_kw={\'tag\': tag},\n
)\n
sale_order_line = sale_order.newContent(\n
portal_type=sale_order_line_portal_type,\n
resource=setup_service_relative_url,\n
quantity=1,\n
price=0,\n
aggregate_value_list=[software_instance, subscription, software_release_document],\n
activate_kw={\'tag\': tag},\n
)\n
portal.portal_workflow.doActionFor(sale_order, "order_action")\n
\n
# Update Open Order\n
# does this order have a client-specific Open Order\n
open_order = portal.portal_catalog.getResultValue(\n
default_destination_section_uid=person.getUid(),\n
portal_type="Open Sale Order",\n
validation_state="validated")\n
if open_order is None:\n
person_slap_interface_state = person.getSlapState()\n
if person_slap_interface_state == \'open_order_created\':\n
open_order_url = context.portal_workflow.getInfoFor(\n
ob=person, name=\'open_order_url\',\n
wf_id=\'person_slap_interface_workflow\')\n
open_order = portal.restrictedTraverse(open_order_url)\n
else:\n
raise ValueError(\'Person has no open order created\')\n
\n
now = DateTime()\n
start_date = getClosestDate(target_date=now, precision=\'day\', before=1)\n
# 12 months of subscription by default\n
stop_date = addToDate(getClosestDate(target_date=now, precision=\'month\', before=1), year=1)\n
\n
subscription_service_relative_url = portal.portal_preferences.getPreferredInstanceSubscriptionResource()\n
open_order.newContent(\n
portal_type="Open Sale Order Line",\n
title=software_title,\n
aggregate_value=subscription,\n
start_date=start_date,\n
stop_date=stop_date,\n
quantity=1,\n
quantity_unit="unit/piece",\n
price=1,\n
price_currency="currency_module/EUR",\n
specialise=sale_order.getSpecialise(portal_type="Sale Trade Condition"),\n
# XXX Hardcoded values\\n\n
resource=subscription_service_relative_url,\n
destination_value=person,\n
destination_section_value=person,\n
source="organisation_module/vifib_internet",\n
source_section="organisation_module/vifib_internet",\n
activate_kw={\'tag\': tag},\n
)\n
\n
# Find Computer partition\n
# XXX Link subscript to open order\n
else:\n else:\n
# Update existing software instance\n request_hosting_subscription.edit(\n
request_software_instance.edit(\n
text_content=instance_xml,\n text_content=instance_xml,\n
source_reference=software_type,\n source_reference=software_type,\n
sla_xml=sla_xml,\n sla_xml=sla_xml,\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag},\n
)\n )\n
if state == \'started\':\n \n
request_software_instance.startRequested()\n request_hosting_subscription.HostingSubscription_requestRootSoftwareInstance(tag, person=person)\n
request_software_instance.activate(after_tag=tag).requestStartComputerPartition()\n
elif state == \'stopped\':\n
request_software_instance.stopRequested()\n
request_software_instance.activate(after_tag=tag).requestStopComputerPartition()\n
]]></string> </value> ]]></string> </value>
......
493 494
\ 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