Commit cef377c3 authored by Romain Courteaud's avatar Romain Courteaud

Migrate Sale Order creation.

Sale Order creation is now done in an interaction workflow triggered by the
instance state change.
parent a4ba8164
719 720
\ No newline at end of file \ No newline at end of file
<base_category_list>
<portal_type id="Slave Instance">
<item>causality</item>
</portal_type>
<portal_type id="Software Instance">
<item>causality</item>
</portal_type>
</base_category_list>
\ No newline at end of file
<workflow_chain>
<chain>
<type>Slave Instance</type>
<workflow>instance_accounting_slap_interaction_workflow</workflow>
</chain>
<chain>
<type>Software Instance</type>
<workflow>instance_accounting_slap_interaction_workflow</workflow>
</chain>
</workflow_chain>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionWorkflowDefinition" module="Products.ERP5.InteractionWorkflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>creation_guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>instance_accounting_slap_interaction_workflow</string> </value>
</item>
<item>
<key> <string>manager_bypass</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Init script Interaction Workflow</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Interaction" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interactions</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>Instance_changePromiseState</string>
</list>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>change_instance_promise_state</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>requestStart</string>
<string>requestStop</string>
<string>requestDestroy</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Slave Instance</string>
<string>Software Instance</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Scripts" module="Products.DCWorkflow.Scripts"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>scripts</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,56 +50,36 @@ ...@@ -50,56 +50,36 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>instance = state_change[\'object\']\n
hosting_subscription = instance.getSpecialiseValue(portal_type="Hosting Subscription")\n
from DateTime import DateTime\n portal = instance.getPortalObject()\n
\n \n
portal = context.getPortalObject()\n # Check if instance is allocated\n
\n partition = instance.getAggregateValue(portal_type="Computer Partition")\n
# copy and paste from\n # Get current delivery\n
# portal_workflow/person_slap_interface_workflow/scripts/Person_requestSoftwareInstance\n delivery = instance.getCausalityValue(portal_type=["Sale Order", "Sale Packing List"])\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\n # Get latest workflow transition\n
# The software instance is already under creation but can not be fetched from catalog\n state = instance.getSlapState()\n
# As it is not possible to fetch informations, it is better to raise an error\n started = "start_requested"\n
raise NotImplementedError(tag)\n stopped = "stop_requested"\n
hosting_subscription = context\n destroyed = "destroy_requested"\n
assert state in [started, stopped, destroyed]\n
# Get all needed services\n
setup_service_relative_url = portal.portal_preferences.getPreferredInstanceSetupResource()\n
setup_service = portal.restrictedTraverse(setup_service_relative_url)\n
# Get software release\n
software_release_document = portal.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n
url_string=instance.getRootSoftwareReleaseUrl())\n
assert software_release_document is not None\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 Packing List"\n
hosting_subscription_portal_type = "Hosting Subscription"\n
if hosting_subscription.isRootSlave():\n
software_instance_portal_type = "Slave Instance"\n
else:\n
software_instance_portal_type = "Software Instance"\n
\n
# Mostly copy and paste from\n
# portal_workflow/person_slap_interface_workflow/scripts/Person_requestSoftwareInstance\n
request_software_instance = hosting_subscription.portal_catalog.getResultValue(\n
portal_type=software_instance_portal_type,\n
title=hosting_subscription.getTitle(),\n
root_uid=hosting_subscription.getUid(),\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
service = portal.restrictedTraverse(setup_service_relative_url)\n
request_software_instance = portal.getDefaultModule(portal_type=software_instance_portal_type).newContent(\n
portal_type=software_instance_portal_type,\n
source_reference=hosting_subscription.getSourceReference(),\n
title=hosting_subscription.getTitle(),\n
text_content=hosting_subscription.getTextContent(),\n
sla_xml=hosting_subscription.getSlaXml(),\n
activate_kw={\'tag\': tag},\n
**portal.Base_getNewSoftwareInstanceCoordinate()\n
)\n
request_software_instance.portal_workflow.doActionFor(request_software_instance,\n
\'validate_action\')\n
\n \n
software_release_document = context.portal_catalog.getResultValue(\n if (partition is None):\n
portal_type=\'Software Release\',\n # If partition is not allocated yet, only a sale order can be instanciated\n
url_string=hosting_subscription.getRootSoftwareReleaseUrl())\n if (delivery is None):\n
assert state != destroyed\n
\n \n
sale_order = portal.getDefaultModule(portal_type=sale_order_portal_type).newContent(\n sale_order = portal.getDefaultModule(portal_type=sale_order_portal_type).newContent(\n
portal_type=sale_order_portal_type,\n portal_type=sale_order_portal_type,\n
...@@ -114,67 +94,43 @@ if (request_software_instance is None):\n ...@@ -114,67 +94,43 @@ if (request_software_instance is None):\n
source_section="organisation_module/vifib_internet",\n source_section="organisation_module/vifib_internet",\n
quantity_unit="unit/piece",\n quantity_unit="unit/piece",\n
price_currency="currency_module/EUR",\n price_currency="currency_module/EUR",\n
activate_kw={\'tag\': tag},\n
)\n )\n
sale_order_line = sale_order.newContent(\n sale_order_line = sale_order.newContent(\n
portal_type=sale_order_line_portal_type,\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
price=service.getSaleSupplyLineBasePrice(),\n price=service.getSaleSupplyLineBasePrice(),\n
aggregate_value_list=[request_software_instance,\n aggregate_value_list=[instance,\n
hosting_subscription,\n hosting_subscription,\n
software_release_document\n software_release_document\n
],\n ],\n
activate_kw={\'tag\': tag},\n
)\n )\n
#portal.portal_workflow.doActionFor(sale_order, "order_action")\n
# XXX: Do not verify security\n
sale_order.order()\n sale_order.order()\n
\n \n
hosting_subscription_predecessor_list = hosting_subscription.getPredecessorList()\n else:\n
hosting_subscription_predecessor_list.append(request_software_instance.getRelativeUrl())\n assert delivery.getPortalType() == sale_order_portal_type\n
hosting_subscription.edit(predecessor_list=hosting_subscription_predecessor_list)\n if state == destroyed:\n
\n # Can destroy the instance before allocation\n
# Find Computer partition\n delivery.cancel()\n
# XXX Link subscript to open order\n else:\n
# Update the software release if it has been changed before allocation\n
sale_order_line = delivery.contentValues(portal_type=sale_order_line_portal_type)[0]\n
if sale_order_line.getAggregate(portal_type=\'Software Release\') != instance.getRootSoftwareReleaseUrl():\n
aggregate_list = [instance.getRootSoftwareReleaseUrl(), \n
instance.getRelativeUrl(),\n
hosting_subscription.getRelativeUrl()]\n
sale_order_line.edit(aggregate_list=aggregate_list)\n
else:\n else:\n
# Update existing software instance\n raise NotImplementedError\n
request_software_instance.edit(\n </string> </value>
text_content=hosting_subscription.getTextContent(),\n
source_reference=hosting_subscription.getSourceReference(),\n
sla_xml=hosting_subscription.getSlaXml(),\n
activate_kw={\'tag\': tag},\n
)\n
for predecessor_related in request_software_instance.getPredecessorRelatedValueList():\n
predecessor_list = predecessor_related.getPredecessorList()\n
predecessor_list.remove(request_software_instance.getRelativeUrl())\n
predecessor_related.setPredecessorList(predecessor_list)\n
\n
hosting_subscription_predecessor_list = hosting_subscription.getPredecessorList()\n
hosting_subscription_predecessor_list.append(request_software_instance.getRelativeUrl())\n
hosting_subscription.setPredecessorList(hosting_subscription_predecessor_list)\n
\n
if hosting_subscription.getSlapState() == \'start_requested\':\n
request_software_instance.startRequested()\n
if not new_one:\n
request_software_instance.activate(after_tag=tag).requestStartComputerPartition()\n
elif hosting_subscription.getSlapState() == \'stop_requested\':\n
request_software_instance.stopRequested()\n
if not new_one:\n
request_software_instance.activate(after_tag=tag).requestStopComputerPartition()\n
\n
return request_software_instance\n
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, person_relative_url</string> </value> <value> <string>state_change</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>HostingSubscription_requestRootSoftwareInstance</string> </value> <value> <string>Instance_changePromiseState</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Variables" module="Products.DCWorkflow.Variables"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>variables</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Worklists" module="Products.DCWorkflow.Worklists"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>worklists</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1 2
\ No newline at end of file \ No newline at end of file
Slave Instance | causality
Software Instance | causality
\ No newline at end of file
Slave Instance | instance_accounting_slap_interaction_workflow
Software Instance | instance_accounting_slap_interaction_workflow
\ No newline at end of file
instance_accounting_slap_interaction_workflow
\ No newline at end of file
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
<item>business_application</item> <item>business_application</item>
</portal_type> </portal_type>
<portal_type id="Slave Instance"> <portal_type id="Slave Instance">
<item>aggregate</item>
<item>specialise</item> <item>specialise</item>
</portal_type> </portal_type>
<portal_type id="Software Instance"> <portal_type id="Software Instance">
<item>aggregate</item>
<item>specialise</item> <item>specialise</item>
</portal_type> </portal_type>
<portal_type id="Software Instance Module"> <portal_type id="Software Instance Module">
......
12 13
\ No newline at end of file \ No newline at end of file
Hosting Subscription Module | business_application Hosting Subscription Module | business_application
Slave Instance | aggregate
Slave Instance | specialise Slave Instance | specialise
Software Instance Module | business_application Software Instance Module | business_application
Software Instance | aggregate
Software Instance | specialise Software Instance | specialise
\ 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