Commit 7593c903 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Create movements for ComputerNetwork and HostingSubscription

Create Internal Packing Lists to transfer ownership/project of ComputerNetwork and Hosting Subscriptions.
parent 9a0557f9
"""
Create an internal Packing List and attach the computer
"""
from DateTime import DateTime
from zExceptions import Unauthorized
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue()
if user.getRelativeUrl() != context.getSourceAdministration():
raise Unauthorized("Only the Computer Network owner can transfer it from one location to another.")
portal_type = "Internal Packing List"
source_project = context.Item_getCurrentProjectValue()
source_section = context.Item_getCurrentOwnerValue()
resource_value = context.Item_getResourceValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
destination_section = context.getSourceAdministration()
if source_section is None:
source_section = context.getSourceAdministration()
resource_value = context.product_module.computer
module = context.getDefaultModule(portal_type=portal_type)
line_portal_type = '%s Line' % portal_type
delivery = module.newContent(title="Transfer %s to %s" % (context.getTitle(), destination_project),
source_value=source_section,
source_section_value=source_section,
source_project_value=source_project,
destination=destination_section,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project_value=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=context.getReference(),
quantity_unit=context.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate_value=context)
delivery.confirm()
delivery.stop()
delivery.deliver()
<?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>_params</string> </key>
<value> <string>destination_project=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputerNetwork_createMovement</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
Create an internal Packing List and attach the computer
"""
from DateTime import DateTime
from Products.ERP5Type.Message import translateString
from zExceptions import Unauthorized
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue()
if user.getRelativeUrl() != context.getDestinationSection():
raise Unauthorized("Only the Hosting Scription owner can transfer it from one location to another.")
portal_type = "Internal Packing List"
source_project = context.Item_getCurrentProjectValue()
source_section = context.Item_getCurrentOwnerValue()
resource_value = context.Item_getResourceValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
destination_section = context.getDestinationSection()
if source_section is None:
source_section = context.getDestinationSectionValue()
resource_value = context.product_module.computer
module = context.getDefaultModule(portal_type=portal_type)
line_portal_type = '%s Line' % portal_type
delivery = module.newContent(title="Transfer %s to %s" % (context.getTitle(), destination_project),
source_value=source_section,
source_section_value=source_section,
source_project_value=source_project,
destination=destination_section,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project_value=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=context.getReference(),
quantity_unit=context.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate_value=context)
delivery.confirm()
delivery.stop()
delivery.deliver()
<?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>_params</string> </key>
<value> <string>destination_project=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_createMovement</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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