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
\ No newline at end of file
720
\ 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 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n
<value> <string>instance = state_change[\'object\']\n
hosting_subscription = instance.getSpecialiseValue(portal_type="Hosting Subscription")\n
portal = instance.getPortalObject()\n
\n
portal = context.getPortalObject()\n
\n
# copy and paste from\n
# portal_workflow/person_slap_interface_workflow/scripts/Person_requestSoftwareInstance\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\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
raise NotImplementedError(tag)\n
hosting_subscription = context\n
# Check if instance is allocated\n
partition = instance.getAggregateValue(portal_type="Computer Partition")\n
# Get current delivery\n
delivery = instance.getCausalityValue(portal_type=["Sale Order", "Sale Packing List"])\n
# Get latest workflow transition\n
state = instance.getSlapState()\n
started = "start_requested"\n
stopped = "stop_requested"\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
sale_order_portal_type = "Sale Order"\n
sale_order_line_portal_type = "Sale Order Line"\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
sale_order_line_portal_type = "Sale Packing List"\n
\n
software_release_document = context.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n
url_string=hosting_subscription.getRootSoftwareReleaseUrl())\n
if (partition is None):\n
# If partition is not allocated yet, only a sale order can be instanciated\n
if (delivery is None):\n
assert state != destroyed\n
\n
sale_order = portal.getDefaultModule(portal_type=sale_order_portal_type).newContent(\n
portal_type=sale_order_portal_type,\n
......@@ -114,67 +94,43 @@ if (request_software_instance is None):\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=service.getSaleSupplyLineBasePrice(),\n
aggregate_value_list=[request_software_instance,\n
aggregate_value_list=[instance,\n
hosting_subscription,\n
software_release_document\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
\n
hosting_subscription_predecessor_list = hosting_subscription.getPredecessorList()\n
hosting_subscription_predecessor_list.append(request_software_instance.getRelativeUrl())\n
hosting_subscription.edit(predecessor_list=hosting_subscription_predecessor_list)\n
\n
# Find Computer partition\n
# XXX Link subscript to open order\n
else:\n
assert delivery.getPortalType() == sale_order_portal_type\n
if state == destroyed:\n
# Can destroy the instance before allocation\n
delivery.cancel()\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
# Update existing software instance\n
request_software_instance.edit(\n
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>
raise NotImplementedError\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, person_relative_url</string> </value>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_requestRootSoftwareInstance</string> </value>
<value> <string>Instance_changePromiseState</string> </value>
</item>
</dictionary>
</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
\ No newline at end of file
2
\ 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 @@
<item>business_application</item>
</portal_type>
<portal_type id="Slave Instance">
<item>aggregate</item>
<item>specialise</item>
</portal_type>
<portal_type id="Software Instance">
<item>aggregate</item>
<item>specialise</item>
</portal_type>
<portal_type id="Software Instance Module">
......
12
\ No newline at end of file
13
\ No newline at end of file
Hosting Subscription Module | business_application
Slave Instance | aggregate
Slave Instance | specialise
Software Instance Module | business_application
Software Instance | aggregate
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